def run_async(to_execute, *args, **kwargs):
 callback = kwargs.pop('at_return', None)
 errback = kwargs.pop('at_err', None)
 callback_kwargs = kwargs.pop('at_return_kwargs', {})
 errback_kwargs = kwargs.pop('at_err_kwargs', {})
 if callable(to_execute):
  deferred = threads.deferToThread(to_execute, *args, **kwargs)
 else:
  raise RuntimeError(("'%s' could not be handled by run_async" % to_execute))
 if callback:
  deferred.addCallback(callback, **callback_kwargs)
 deferred.addErrback(errback, **errback_kwargs)

def run_async ( to_execute , * args , ** kwargs ) : callback = kwargs . pop ( 'at_return' , None ) errback = kwargs . pop ( 'at_err' , None ) callback_kwargs = kwargs . pop ( 'at_return_kwargs' , { } ) errback_kwargs = kwargs . pop ( 'at_err_kwargs' , { } ) if callable ( to_execute ) : deferred = threads . deferToThread ( to_execute , * args , ** kwargs ) else : raise RuntimeError ( ( "'%s' could not be handled by run_async" % to_execute ) ) if callback : deferred . addCallback ( callback , ** callback_kwargs ) deferred . addErrback ( errback , ** errback_kwargs )
runs a function or executes a code snippet asynchronously .