multiprocessing callbacks?


Pete Hunt

Hey, everyone -

I'm trying to use multiprocessing to create a process pool similar to
multiprocessing.Pool, except that it works across multiple hosts. For
various reasons, I would like the result of async_apply() to return a
Twisted Deferred object.

My first attempt at the implementation is:

class DeferredProxy(managers.BaseProxy):
_exposed_ = ("callback","errback","addCallback","addErrback")
def callback(self, v):
return self._callmethod("callback",(v,))

def errback(self, v):
return self._callmethod("errback",(v,))

def addCallback(self, cb):
return self._callmethod("addCallback",(cb,))

def addErrback(self, eb):
return self.__callmethod("adderrback",(eb,))

class DispatchManager(managers.BaseManager):
DispatchManager.register("Deferred", defer.Deferred, DeferredProxy)

This, however, fails, because "cb" and "eb" cannot be pickled. I don't
actually need to pickle them, though, because I want them to run on
the machine on which they were created. Is there a way, in
multiprocessing, that I can pass some sort of "callback" around that
serves as a proxy to a remote function?

Thanks in advance,



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question