Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
def slow_ser(obj):
    """Serialize a complex object (like a closure)."""
    return serialization.serialize(obj, True)
Exemplo n.º 7
0
def slow_ser(obj):
    """Serialize a complex object (like a closure)."""
    return serialization.serialize(obj, True)
Exemplo n.º 8
0
 def serialize(self):
     return serialize(self)