def _function_handler(function, args, kwargs, pipe): """Runs the actual function in separate process and returns its result.""" signal.signal(signal.SIGINT, signal.SIG_IGN) result = execute(function, *args, **kwargs) send_result(pipe, result)
def execute_next_task(task): payload = task.payload task.timestamp = time.time() task.set_running_or_notify_cancel() result = execute(payload.function, *payload.args, **payload.kwargs) if isinstance(result, BaseException): task.future.set_exception(result) else: task.future.set_result(result)
def worker_process(params, channel): """The worker process routines.""" signal(SIGINT, SIG_IGN) if params.initializer is not None: if not run_initializer(params.initializer, params.initargs): os._exit(1) try: for task in worker_get_next_task(channel, params.max_tasks): payload = task.payload result = execute(payload.function, *payload.args, **payload.kwargs) send_result(channel, Result(task.id, result)) except (EnvironmentError, OSError) as error: os._exit(error.errno if error.errno else 1) except EOFError: os._exit(0)
def process_chunk(function, chunk): """Processes a chunk of the iterable passed to map dealing with errors.""" return [execute(function, *args) for args in chunk]
def map_function(function, chunk): """Processes a chunk of the iterable passed to map dealing with errors.""" return [execute(function, *args) for args in chunk]