def _main(): arguments_json_path = sys.argv[1] with open(arguments_json_path) as f: arguments = pickle.loads(f.read()) # arguments_json_path is a temporary file created by the parent process. # so we remove it here os.remove(arguments_json_path) task_id = arguments['task_id'] port = arguments['port'] messenger = _Messenger(task_id=task_id, port=port) function = arguments['function'] operation_arguments = arguments['operation_arguments'] context_dict = arguments['context'] try: ctx = context_dict['context_cls'].instantiate_from_dict(**context_dict['context']) except BaseException as e: messenger.failed(e) return try: messenger.started() task_func = imports.load_attribute(function) aria.install_aria_extensions() for decorate in process_executor.decorate(): task_func = decorate(task_func) task_func(ctx=ctx, **operation_arguments) ctx.close() messenger.succeeded() except BaseException as e: ctx.close() messenger.failed(e)
def _main(): arguments_json_path = sys.argv[1] with open(arguments_json_path) as f: arguments = jsonpickle.loads(f.read()) # arguments_json_path is a temporary file created by the parent process. # so we remove it here os.remove(arguments_json_path) task_id = arguments['task_id'] port = arguments['port'] messenger = _Messenger(task_id=task_id, port=port) messenger.started() operation_mapping = arguments['operation_mapping'] operation_inputs = arguments['operation_inputs'] context_dict = arguments['context'] # This is required for the instrumentation work properly. # See docstring of `remove_mutable_association_listener` for further details storage_type.remove_mutable_association_listener() with instrumentation.track_changes() as instrument: try: ctx = serialization.operation_context_from_dict(context_dict) _patch_session(ctx=ctx, messenger=messenger, instrument=instrument) task_func = imports.load_attribute(operation_mapping) aria.install_aria_extensions() for decorate in process_executor.decorate(): task_func = decorate(task_func) task_func(ctx=ctx, **operation_inputs) messenger.succeeded(tracked_changes=instrument.tracked_changes) except BaseException as e: messenger.failed(exception=e, tracked_changes=instrument.tracked_changes)
def _processor(self): while not self._stopped: try: task = self._queue.get(timeout=1) self._task_started(task) try: task_func = imports.load_attribute(task.operation_mapping) task_func(ctx=task.context, **task.inputs) self._task_succeeded(task) except BaseException as e: self._task_failed(task, exception=e) # Daemon threads except BaseException: pass
def _processor(self): while not self._stopped: try: task = self._queue.get(timeout=1) self._task_started(task) try: task_func = imports.load_attribute(task.function) arguments = dict(arg.unwrapped for arg in task.arguments.values()) task_func(ctx=task.context, **arguments) self._task_succeeded(task) except BaseException as e: self._task_failed(task, exception=e, traceback=exceptions.get_exception_as_string(*sys.exc_info())) # Daemon threads except BaseException as e: pass