def worker_process(params, channel): """The worker process routines.""" signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGTERM, lambda signum, frame: _exit(0)) if params.initializer is not None: if not run_initializer(params.initializer, params.initargs): _exit(1) # store children pids which may start together with initializer init_pids = [child.pid for child in _proc_children()] try: for task in worker_get_next_task(channel, params.max_tasks): payload = task.payload result = process_execute( payload.function, *payload.args, **payload.kwargs) send_result(channel, Result(task.id, result)) for child in _proc_children(): # kill child process if it wasn't finished together with task if child.pid not in init_pids: child.kill() except (EnvironmentError, OSError, RuntimeError) as error: _exit(error.errno if error.errno else 1) except EOFError: _exit(0)
def worker_thread(context): """The worker thread routines.""" queue = context.task_queue parameters = context.worker_parameters if parameters.initializer is not None: if not run_initializer(parameters.initializer, parameters.initargs): context.state = ERROR return for task in get_next_task(context, parameters.max_tasks): execute_next_task(task) queue.task_done()
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 worker_thread(context): """The worker thread routines.""" queue = context.task_queue parameters = context.worker_parameters if parameters.initializer is not None: if not run_initializer(parameters.initializer, parameters.initargs): context.state = ERROR return current_thread = threading.current_thread() for task in get_next_task(context, parameters.max_tasks): if current_thread.is_shutdown: break task.worker_id = current_thread.ident execute_next_task(task) queue.task_done()