<s> import errno <EOL> import os <EOL> import sys <EOL> import gevent <EOL> import gevent . monkey <EOL> gevent . monkey . patch_all ( ) <EOL> pid = None <EOL> awaiting_child = [ ] <EOL> def handle_sigchld ( * args ) : <EOL> gevent . sleep ( ) <EOL> awaiting_child . pop ( ) <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> import signal <EOL> if hasattr ( signal , '<STR_LIT>' ) : <EOL> assert signal . getsignal ( signal . SIGCHLD ) == signal . SIG_DFL <EOL> signal . signal ( signal . SIGCHLD , handle_sigchld ) <EOL> handler = signal . getsignal ( signal . SIGCHLD ) <EOL> assert signal . getsignal ( signal . SIGCHLD ) is handle_sigchld , handler <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def forkpty ( ) : <EOL> return os . forkpty ( ) [ <NUM_LIT:0> ] <EOL> funcs = ( os . fork , forkpty ) <EOL> else : <EOL> funcs = ( os . fork , ) <EOL> for func in funcs : <EOL> awaiting_child = [ True ] <EOL> pid = func ( ) <EOL> if not pid : <EOL> gevent . sleep ( <NUM_LIT> ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> else : <EOL> timeout = gevent . Timeout ( <NUM_LIT:1> ) <EOL> try : <EOL> while awaiting_child : <EOL> gevent . sleep ( <NUM_LIT> ) <EOL> wpid , status = os . waitpid ( - <NUM_LIT:1> , os . WNOHANG ) <EOL> if wpid != pid : <EOL> raise AssertionError ( "<STR_LIT>" , <EOL> wpid , pid , func ) <EOL> try : <EOL> wpid , status = os . waitpid ( - <NUM_LIT:1> , os . WNOHANG ) <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> except OSError as e : <EOL> assert e . errno == errno . ECHILD <EOL> except gevent . Timeout as t : <EOL> if timeout is not t : <EOL> raise <EOL> raise AssertionError ( "<STR_LIT>" , func ) <EOL> finally : <EOL> timeout . cancel ( ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> else : <EOL> print ( "<STR_LIT>" ) </s>
