<s> import gevent <EOL> import signal <EOL> alive = <NUM_LIT:0> <EOL> def next ( argA = None , argB = None ) : <EOL> try : <EOL> if alive > <NUM_LIT:0> : <EOL> signal . setitimer ( signal . ITIMER_REAL , <NUM_LIT> ) <EOL> else : <EOL> signal . setitimer ( signal . ITIMER_REAL , <NUM_LIT:0> ) <EOL> gevent . sleep ( <NUM_LIT:0> ) <EOL> except : <EOL> pass <EOL> signal . signal ( signal . SIGALRM , next ) <EOL> def removeOne ( g ) : <EOL> global alive <EOL> alive -= <NUM_LIT:1> <EOL> def spawn ( method , * args , ** kr ) : <EOL> global alive <EOL> g = gevent . spawn ( method , * args , ** kr ) <EOL> alive += <NUM_LIT:1> <EOL> next ( ) <EOL> g . link ( removeOne ) <EOL> return g <EOL> def spawn_after ( seconds , method , * args , ** kwargs ) : <EOL> global alive <EOL> g = gevent . spawn_later ( seconds , method , * args , ** kr ) <EOL> alive += <NUM_LIT:1> <EOL> g . link ( removeOne ) <EOL> return g <EOL> def spawn_n ( method , * args , ** kwargs ) : <EOL> global alive <EOL> g = gevent . spawn_raw ( method , * args , ** kr ) <EOL> alive += <NUM_LIT:1> <EOL> g . link ( removeOne ) <EOL> sleep = gevent . sleep <EOL> getcurrent = gevent . getcurrent <EOL> def wait_all ( ) : <EOL> """<STR_LIT>""" <EOL> global alive <EOL> try : <EOL> while alive > <NUM_LIT:0> : <EOL> gevent . sleep ( <NUM_LIT:1> ) <EOL> finally : <EOL> signal . setitimer ( signal . ITIMER_REAL , <NUM_LIT:0> ) </s>
