def work_once(condor_id, req_socket, task): """Request and/or complete a single unit of work.""" # get an assignment if task is None: cargo.send_pyobj_gz( req_socket, cargo.labor2.ApplyMessage(condor_id), ) task = cargo.recv_pyobj_gz(req_socket) if task is None: logger.info("received null assignment; terminating") return None # complete the assignment try: cargo.labor2._current_task = task logger.info("starting work on task %s", task.key) result = task() except KeyboardInterrupt, error: logger.warning("interruption during task %s", task.key) cargo.send_pyobj_gz( req_socket, cargo.labor2.InterruptedMessage(condor_id, task.key), ) req_socket.recv()
def work_once(condor_id, req_socket, task): """Request and/or complete a single unit of work.""" # get an assignment if task is None: cargo.send_pyobj_gz(req_socket, cargo.labor2.ApplyMessage(condor_id)) task = cargo.recv_pyobj_gz(req_socket) if task is None: logger.info("received null assignment; terminating") return None # complete the assignment try: seed = abs(hash(task.key)) logger.info("setting PRNG seed to %s", seed) numpy.random.seed(seed) random.seed(numpy.random.randint(2 ** 32)) logger.info("starting work on task %s", task.key) result = task() except KeyboardInterrupt, error: logger.warning("interruption during task %s", task.key) cargo.send_pyobj_gz(req_socket, cargo.labor2.InterruptedMessage(condor_id, task.key)) req_socket.recv()
except KeyboardInterrupt, error: logger.warning("interruption during task %s", task.key) cargo.send_pyobj_gz( req_socket, cargo.labor2.InterruptedMessage(condor_id, task.key), ) req_socket.recv() except BaseException, error: description = traceback.format_exc(error) logger.warning("error during task %s:\n%s", task.key, description) cargo.send_pyobj_gz( req_socket, cargo.labor2.ErrorMessage(condor_id, task.key, description), ) req_socket.recv() else: logger.info("finished task %s", task.key) cargo.send_pyobj_gz( req_socket, cargo.labor2.DoneMessage(condor_id, task.key, result), ) return cargo.recv_pyobj_gz(req_socket) cargo.labor2._current_task = None