<s> import asyncoro . disasyncoro as asyncoro <EOL> from asyncoro . discoro import * <EOL> from asyncoro . discoro_schedulers import RemoteCoroScheduler <EOL> class C ( object ) : <EOL> def __init__ ( self , i , n , client ) : <EOL> self . i = i <EOL> self . n = n <EOL> self . client = client <EOL> def rcoro_proc ( coro = None ) : <EOL> import os <EOL> cobj = yield coro . receive ( ) <EOL> if not cobj : <EOL> raise StopIteration <EOL> inp_file = '<STR_LIT>' % cobj . i <EOL> out_file = '<STR_LIT>' % cobj . i <EOL> with open ( inp_file , '<STR_LIT:r>' ) as inp_fd : <EOL> with open ( out_file , '<STR_LIT:w>' ) as out_fd : <EOL> for lineno , line in enumerate ( inp_fd , start = <NUM_LIT:1> ) : <EOL> out_fd . write ( '<STR_LIT>' % ( lineno , len ( line ) - <NUM_LIT:1> ) ) <EOL> yield coro . sleep ( cobj . n ) <EOL> result = yield asyncoro . AsynCoro ( ) . send_file ( cobj . client . location , out_file , overwrite = True , <EOL> timeout = <NUM_LIT:30> ) <EOL> cobj . client . send ( result ) <EOL> os . remove ( inp_file ) <EOL> os . remove ( out_file ) <EOL> def client_proc ( job_id , rcoro , coro = None ) : <EOL> if ( yield asyncoro . AsynCoro ( ) . send_file ( rcoro . location , '<STR_LIT>' % job_id , <EOL> timeout = <NUM_LIT:30> ) ) < <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' % rcoro . location ) <EOL> rcoro . send ( None ) <EOL> raise StopIteration ( - <NUM_LIT:1> ) <EOL> obj = C ( job_id , random . uniform ( <NUM_LIT:5> , <NUM_LIT:8> ) , coro ) <EOL> if ( yield rcoro . deliver ( obj ) ) != <NUM_LIT:1> : <EOL> print ( '<STR_LIT>' % rcoro . location ) <EOL> raise StopIteration ( - <NUM_LIT:1> ) <EOL> result = yield coro . receive ( ) <EOL> if result < <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' % obj . i ) <EOL> raise StopIteration ( - <NUM_LIT:1> ) <EOL> output = os . path . join ( asyncoro . AsynCoro ( ) . dest_path , '<STR_LIT>' % obj . i ) <EOL> print ( '<STR_LIT>' % ( obj . i ) ) <EOL> def submit_jobs_proc ( computation , njobs , coro = None ) : <EOL> if ( yield computation . schedule ( ) ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> for i in range ( njobs ) : <EOL> rcoro = yield rcoro_scheduler . schedule ( rcoro_proc ) <EOL> if isinstance ( rcoro , asyncoro . Coro ) : <EOL> asyncoro . Coro ( client_proc , i , rcoro ) <EOL> yield rcoro_scheduler . finish ( close = True ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import logging , random , os <EOL> asyncoro . logger . setLevel ( logging . DEBUG ) <EOL> Scheduler ( ) <EOL> computation = Computation ( [ C ] ) <EOL> rcoro_scheduler = RemoteCoroScheduler ( computation ) <EOL> asyncoro . Coro ( submit_jobs_proc , computation , <NUM_LIT:10> ) </s>
