#NEWLINE# def asyncRun( self , cb , * args , **kwargs ) : #NEWLINE# #INDENT# "Helper call to run a callback `cb` within the task's main loop.\n        Returns an instance of Future() that can be waited for obtain\n        the result of computation. The callback will be run only once.\n        " #NEWLINE# def _future_execute( f , cb , * args , **kwargs ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if f . set_running_or_notify_cancel ( ) : #NEWLINE# #INDENT# f . set_result ( cb ( * args , ** kwargs ) ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# f . set_exception ( e ) #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# def _future_cancel( handle , f ) : #NEWLINE# #INDENT# if f . cancelled ( ) : #NEWLINE# #INDENT# glib . source_remove ( handle ) #NEWLINE# #UNINDENT# #UNINDENT# f = Future ( ) #NEWLINE# handle = glib . idle_add ( partial ( _future_execute , f , cb , * args , ** kwargs ) ) #NEWLINE# f . add_done_callback ( partial ( _future_cancel , handle ) ) #NEWLINE# return f