[Twisted-Python] Running callbacks in a non-main thread

Bob Ippolito bob at redivi.com
Fri Feb 3 17:13:04 MST 2006


On Feb 3, 2006, at 2:29 PM, Gabe Rudy wrote:

> I realize that the point of deferreds is to have process/network  
> intensive
> tasks work on in their own thread and send the results to callback  
> function
> in the main thread, but is there away to have a deferred process it's
> callback in a non-main thread?

No, that's not the point of deferreds.  A Deferred is just an  
object.  It doesn't know anything at all about threads, and it sure  
as hell doesn't implement any sort of thread safety.  All it really  
does it encapsulate a call chain.

Technically a Deferred will process its callbacks in the same thread  
that callback or errback was invoked in.  If you feel the need to do  
that, your design is probably fubar though.

... there is *one* function in Twisted that will invoke a callable in  
a thread and return a Deferred, but that's hardly a common usage.

-bob





More information about the Twisted-Python mailing list