예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
def slow_deser(blob):
    """Deserialize a complex object."""
    return serialization.deserialize(blob)
예제 #7
0
def slow_deser(blob):
    """Deserialize a complex object."""
    return serialization.deserialize(blob)
예제 #8
0
 def deserialize(self, payload):
     return deserialize(payload)