<s> """<STR_LIT>""" <EOL> import logging <EOL> import webapp2 <EOL> class ContextCompletionHandler ( webapp2 . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> from furious . async import Async <EOL> from furious import context <EOL> count = self . request . get ( '<STR_LIT>' , <NUM_LIT:5> ) <EOL> with context . new ( persist_async_results = True ) as ctx : <EOL> ctx . set_event_handler ( '<STR_LIT>' , <EOL> Async ( context_complete , args = [ ctx . id ] ) ) <EOL> for i in xrange ( int ( count ) ) : <EOL> ctx . add ( target = async_worker , args = [ ctx . id , i ] ) <EOL> logging . info ( '<STR_LIT>' , i ) <EOL> logging . info ( '<STR_LIT>' ) <EOL> self . response . out . write ( '<STR_LIT>' ) <EOL> def async_worker ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> logging . info ( '<STR_LIT>' , * args ) <EOL> return args <EOL> def context_complete ( context_id ) : <EOL> """<STR_LIT>""" <EOL> logging . info ( '<STR_LIT>' , context_id ) <EOL> from furious . context import get_current_async_with_context <EOL> _ , context = get_current_async_with_context ( ) <EOL> if not context : <EOL> logging . error ( "<STR_LIT>" ) <EOL> return <EOL> for task_id , result in context . result . items ( ) : <EOL> logging . info ( "<STR_LIT>" ) <EOL> logging . info ( "<STR_LIT>" , task_id , result ) <EOL> return context_id </s>
