<s> import logging <EOL> from datetime import datetime , timedelta <EOL> asyncio = None <EOL> from rx . disposables import Disposable , SingleAssignmentDisposable , CompositeDisposable <EOL> from rx . concurrency . scheduler import Scheduler <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> class AsyncIOScheduler ( Scheduler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , loop = None ) : <EOL> global asyncio <EOL> import rx <EOL> asyncio = rx . config [ '<STR_LIT>' ] <EOL> self . loop = loop or asyncio . get_event_loop ( ) <EOL> def schedule ( self , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> scheduler = self <EOL> disposable = SingleAssignmentDisposable ( ) <EOL> def interval ( ) : <EOL> disposable . disposable = action ( scheduler , state ) <EOL> handle = [ self . loop . call_soon ( interval ) ] <EOL> def dispose ( ) : <EOL> handle [ <NUM_LIT:0> ] . cancel ( ) <EOL> return CompositeDisposable ( disposable , Disposable ( dispose ) ) <EOL> def schedule_relative ( self , duetime , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> scheduler = self <EOL> seconds = self . to_relative ( duetime ) / <NUM_LIT> <EOL> if seconds == <NUM_LIT:0> : <EOL> return scheduler . schedule ( action , state ) <EOL> disposable = SingleAssignmentDisposable ( ) <EOL> def interval ( ) : <EOL> disposable . disposable = action ( scheduler , state ) <EOL> handle = [ self . loop . call_later ( seconds , interval ) ] <EOL> def dispose ( ) : <EOL> handle [ <NUM_LIT:0> ] . cancel ( ) <EOL> return CompositeDisposable ( disposable , Disposable ( dispose ) ) <EOL> def schedule_absolute ( self , duetime , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> duetime = self . to_datetime ( duetime ) <EOL> return self . schedule_relative ( duetime - self . now ( ) , action , state ) <EOL> def schedule_periodic ( self , period , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> scheduler = self <EOL> seconds = self . to_relative ( period ) / <NUM_LIT> <EOL> if seconds == <NUM_LIT:0> : <EOL> return scheduler . schedule ( action , state ) <EOL> disposable = SingleAssignmentDisposable ( ) <EOL> def interval ( ) : <EOL> disposable . disposable = action ( state ) <EOL> scheduler . schedule_periodic ( period , action , state ) <EOL> handle = [ self . loop . call_later ( seconds , interval ) ] <EOL> def dispose ( ) : <EOL> handle [ <NUM_LIT:0> ] . cancel ( ) <EOL> return CompositeDisposable ( disposable , Disposable ( dispose ) ) <EOL> def now ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . to_datetime ( self . loop . time ( ) ) </s>
