def dispatch_callback (_callback, _return_callback, _raise_callback, _reactor, _t = _tracer, _e = _enforcer) : _e and ( _e.enforce_callable_spec (_callback, 0) and _e.enforce_callable_spec_or_none (_return_callback, 1) and _e.enforce_callable_spec_or_none (_raise_callback, 3) and _e.enforce_instance_or_none (_reactor, reactor.Reactor)) if _reactor is None : _t.d and _t.d ('dispatching callback', callback = _callback) _callback_callable, _callback_list_arguments, _callback_dict_arguments = callables.unwrap_callable_spec (_callback) try : _callback_outcome = _callback_callable (* _callback_list_arguments, ** _callback_dict_arguments) _callback_error = None except Exception : _t.e and _t.e ('error encountered while dispatching callback', callback = _callback, __exception = True) _callback_error = sys.exc_info () if _callback_error is None : _final_callback = (_raise_callback, _callback_error, None) if _raise_callback is not None else None else : _final_callback = (_return_callback, (_callback_outcome,), None) if _return_callback is not None else None if _final_callback is not None : _t.d and _t.d ('dispatching outcome callback', callback = _final_callback) dispatch_callback (_final_callback, None, None, None, _t, _e) else : _t.d and _t.d ('enqueueing callback', callback = _callback) _dispatch = lambda : dispatch_callback (_callback, _return_callback, _raise_callback, None, _t = _t, _e = _e) _reactor.enqueue_immediate_task (_dispatch) return
def dispatch_action_and_wait (_action, _timeout, _raise_if_timeout, _return_if_timeout, _reactor, _t = _tracer, _e = _enforcer) : _raise_if_timeout, _return_if_timeout = ( coerce_raise_or_return_if_timeout ( _timeout, _raise_if_timeout, _return_if_timeout, _mandatory, _mandatory, _t, _e)) _e and ( _e.enforce_callable_spec (_action, 2) and _e.enforce_instance (_reactor, reactor.Reactor)) _queue = queue.Queue () _action_callable, _action_list_arguments, _action_dict_arguments = callables.unwrap_callable_spec (_action) _action_list_arguments.append (_queue.put) _action_list_arguments.append (_queue.put) _action_callable (* _action_list_arguments, ** _action_dict_arguments) try : _outcome = _queue.get (True, _timeout) except queue.Empty : _outcome = raise_or_return (_raise_if_timeout, _return_if_timeout, _t, _e) return _outcome