def worker(workerid): """Called to execute a job on a remote host.""" try: with open(INFILE_FMT % workerid) as f: indata = f.read() fun, args, kwargs = serialization.deserialize(indata) result = True, fun(*args, **kwargs) out = serialization.serialize(result, True) except BaseException, exc: result = False, str(exc) out = serialization.serialize(result, False)
def worker(workerid): """Called to execute a job on a remote host.""" try: with open(INFILE_FMT % workerid) as f: indata = f.read() fun, args, kwargs = serialization.deserialize(indata) result = True, fun(*args, **kwargs) out = serialization.serialize(result, True) except: result = False, format_remote_exc() out = serialization.serialize(result, False) destfile = OUTFILE_FMT % workerid tempfile = destfile + '.tmp' with open(tempfile, 'w') as f: f.write(out) os.rename(tempfile, destfile)
def _completion(self, jobid): """Called whenever a job finishes.""" with self.jobs_lock: fut, workerid = self.jobs.pop(jobid) if not self.jobs: self.jobs_empty_cond.notify_all() if self.debug: print >>sys.stderr, "job completed: %i" % jobid with open(OUTFILE_FMT % workerid) as f: outdata = f.read() success, result = serialization.deserialize(outdata) if success: fut.set_result(result) else: fut.set_exception(RemoteException(result)) # Clean up communication files. os.unlink(INFILE_FMT % workerid) os.unlink(OUTFILE_FMT % workerid) self._cleanup(jobid)
def _completion(self, jobid): """Called whenever a job finishes.""" with self.jobs_lock: fut, workerid = self.jobs.pop(jobid) if not self.jobs: self.jobs_empty_cond.notify_all() if self.debug: print >> sys.stderr, "job completed: %i" % jobid with open(OUTFILE_FMT % workerid) as f: outdata = f.read() success, result = serialization.deserialize(outdata) if success: fut.set_result(result) else: fut.set_exception(RemoteException(result)) # Clean up communication files. os.unlink(INFILE_FMT % workerid) os.unlink(OUTFILE_FMT % workerid) self._cleanup(jobid)
def slow_deser(blob): """Deserialize a complex object.""" return serialization.deserialize(blob)
def deserialize(self, payload): return deserialize(payload)