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 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 submit(self, fun, *args, **kwargs): """Submit a job to the pool.""" fut = futures.Future() # Start the job. workerid = random_string() funcser = serialization.serialize((fun, args, kwargs), True) with open(INFILE_FMT % workerid, 'w') as f: f.write(funcser) jobid = self._start(workerid) if self.debug: print >>sys.stderr, "job submitted: %i" % jobid # Thread will wait for it to finish. self.wait_thread.wait(OUTFILE_FMT % workerid, jobid) with self.jobs_lock: self.jobs[jobid] = (fut, workerid) return fut
def submit(self, fun, *args, **kwargs): """Submit a job to the pool.""" fut = futures.Future() # Start the job. workerid = random_string() funcser = serialization.serialize((fun, args, kwargs), True) with open(INFILE_FMT % workerid, 'w') as f: f.write(funcser) jobid = self._start(workerid) if self.debug: print >> sys.stderr, "job submitted: %i" % jobid # Thread will wait for it to finish. self.wait_thread.wait(OUTFILE_FMT % workerid, jobid) with self.jobs_lock: self.jobs[jobid] = (fut, workerid) return fut
def slow_ser(obj): """Serialize a complex object (like a closure).""" return serialization.serialize(obj, True)
def slow_ser(obj): """Serialize a complex object (like a closure).""" return serialization.serialize(obj, True)
def serialize(self): return serialize(self)