def _execute_addonsignals_return_call(result, func_name): """If enabled execute AddonSignals return callback""" if G.IPC_OVER_HTTP: return result # Do not return None or AddonSignals will keep waiting till timeout if result is None: result = {} AddonSignals.returnCall(signal=func_name, source_id=G.ADDON_ID, data=result) return result
def _perform_ipc_return_call_instance(instance, func, data): try: result = _call_with_instance(instance, func, data) except Exception as exc: # pylint: disable=broad-except LOG.error('IPC callback raised exception: {exc}', exc=exc) import traceback LOG.error(traceback.format_exc()) result = ipc_convert_exc_to_json(exc) AddonSignals.returnCall(signal=func.__name__, source_id=IPC_ADDON_ID, data=result) return result
def call(self, data): """Routes the call to the function associated to the class""" try: result = _call(self._func, data) except Exception as exc: # pylint: disable=broad-except if exc.__class__.__name__ not in [ 'CacheMiss', 'MetadataNotAvailable' ]: LOG.error('IPC callback raised exception: {exc}', exc=exc) import traceback LOG.error(traceback.format_exc()) result = exc _result = b64encode(pickle.dumps( result, pickle.HIGHEST_PROTOCOL)).decode('ascii') AddonSignals.returnCall(signal=self._func.__name__, source_id=G.ADDON_ID, data=_result)
def return_call(self, data): """In memory reference for the target func, with an automatic AddonSignals.returnCall callback""" try: _data = pickle.loads(b64decode(data)) result = _call(self._func, _data) except Exception as exc: # pylint: disable=broad-except if exc.__class__.__name__ not in [ 'CacheMiss', 'MetadataNotAvailable' ]: LOG.error('IPC callback raised exception: {exc}', exc=exc) import traceback LOG.error(traceback.format_exc()) result = exc _result = b64encode(pickle.dumps( result, pickle.HIGHEST_PROTOCOL)).decode('ascii') AddonSignals.returnCall(signal=self._func.__name__, source_id=G.ADDON_ID, data=_result)
def make_return_call(instance, data): """Makes func return callable through AddonSignals and handles catching, conversion and forwarding of exceptions""" try: result = call(instance, func, data) except Exception as exc: # pylint: disable=broad-except error('IPC callback raised exception: {exc}', exc=exc) import traceback error(g.py2_decode(traceback.format_exc(), 'latin-1')) result = { 'error': exc.__class__.__name__, 'message': unicode(exc), } if g.IPC_OVER_HTTP: return result # Do not return None or AddonSignals will keep waiting till timeout if result is None: result = {} AddonSignals.returnCall(signal=_signal_name(func), source_id=g.ADDON_ID, data=result) return result