<s> from __future__ import absolute_import <EOL> import eventlet <EOL> import eventlet . greenpool <EOL> import eventlet . greenthread <EOL> import eventlet . event <EOL> import eventlet . queue <EOL> import eventlet . timeout <EOL> import eventlet . semaphore <EOL> from . . core import BasicService , Service <EOL> from . . util import defaultproperty <EOL> class AsyncManager ( BasicService ) : <EOL> """<STR_LIT>""" <EOL> stop_timeout = defaultproperty ( int , <NUM_LIT:1> ) <EOL> def __init__ ( self ) : <EOL> self . _greenlets = eventlet . greenpool . GreenPool ( ) <EOL> def do_stop ( self ) : <EOL> if eventlet . greenthread . getcurrent ( ) in self . _greenlets . coroutines_running : <EOL> return eventlet . spawn ( self . do_stop ) . join ( ) <EOL> if self . _greenlets . running ( ) : <EOL> with eventlet . timeout . Timeout ( self . stop_timeout , False ) : <EOL> self . _greenlets . waitall ( ) <EOL> for g in list ( self . _greenlets . coroutines_running ) : <EOL> with eventlet . timeout . Timeout ( <NUM_LIT:1> , False ) : <EOL> g . kill ( ) <EOL> def spawn ( self , func , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _greenlets . spawn ( func , * args , ** kwargs ) <EOL> def spawn_later ( self , seconds , func , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def spawner ( ) : <EOL> self . spawn ( func , * args , ** kwargs ) <EOL> return eventlet . spawn_after ( seconds , spawner ) <EOL> def sleep ( self , seconds ) : <EOL> return eventlet . sleep ( seconds ) <EOL> def queue ( self , * args , ** kwargs ) : <EOL> return eventlet . queue . Queue ( * args , ** kwargs ) <EOL> def event ( self , * args , ** kwargs ) : <EOL> return Event ( * args , ** kwargs ) <EOL> def lock ( self , * args , ** kwargs ) : <EOL> return eventlet . semaphore . Semaphore ( * args , ** kwargs ) <EOL> class Event ( eventlet . event . Event ) : <EOL> def clear ( self ) : <EOL> if not self . ready ( ) : <EOL> return <EOL> self . reset ( ) <EOL> def set ( self ) : <EOL> self . send ( ) <EOL> def wait ( self , timeout = None ) : <EOL> if timeout : <EOL> with eventlet . timeout . Timeout ( timeout , False ) : <EOL> super ( Event , self ) . wait ( ) <EOL> else : <EOL> super ( Event , self ) . wait ( ) </s>
