[Twisted-Python] Returning a Deferred as a result from another Deferred

Ryan Fugger rfugger at gmail.com
Fri Oct 5 15:41:28 MDT 2007


Returning a Deferred as a result from another Deferred seems to be
disallowed by an assertion at the start of the callback chain.  Why is
this?  Right now I have worked around this limitation by wrapping my
Deferred in a list and then unwrapping it in the callback.

Maybe someone can suggest a better approach.  My application takes a
command from one connection and defers processing to a worker thread
to permit potentially-blocking database access.  That worker thread
often will need to send data over another connection to fulfill the
command, and await a reply before the reply can be sent back over the
original command connection.  The worker thread sends data over the
second connection using callFromThread, and this send operation itself
returns a Deferred which fires when the reply is received.  It is this
Deferred that I want to return as a result from the original Deferred
created by deferring to the worker thread in the command handler, so I
can wait until the reply comes from the second connection, and then
reply on the original command connection.  Can someone suggest a
better approach?

Thanks.

Ryan




More information about the Twisted-Python mailing list