[Twisted-web] How to "monitor" parallel executions of Deferreds

Pedro Sanchez psanchez at nortel.com
Thu Aug 25 08:09:37 MDT 2005


I need to implement a function (say, myfunc) that fires several
independent Deferreds (using deferToThread), and that returns a deferred
itself. A client of this function (say, client) is expected to do
something like this:

def client():
    def done(success)
        if success:
           print 'd1 and d2 are done'

    d = myfunc()

myfuct() above does something like this:

def myfunc():
    def checkFunc1(success):

    def checkFunc2(success):

    d = defer.Deferred()
    d1 = deferToThread(func1).addCallback(checkFunc1)
    d2 = deferToThread(func2).addCallback(checkFunc2)

    return d

Clearly d, d1, and d2 in the above are disconnected. And I don't want to
serialize d1 and d2 which would be a way to connect them all.

The problem is I don't know how d should be defined. The idea is that
the 'done' function in the client function is only called when both
threads d1 and d2 are done.

Can you give me any suggestions on how to implement myfunc()?

Thank you,


More information about the Twisted-web mailing list