[Twisted-Python] Running callbacks in a non-main thread
exarkun at divmod.com
Fri Feb 3 21:05:29 EST 2006
On Fri, 3 Feb 2006 18:06:52 -0700, Gabe Rudy <rudy at goldenhelix.com> wrote:
>On Friday 03 February 2006 5:13 pm, Bob Ippolito wrote:
>> 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.
>Ok, thanks for setting me strait. I see that my problem was really I was
>blocking the main thread, and hence the reactor from doing _anything_. I got
>a workable hack now that processes reactor events in a loop until the worker
>thread finishes, then returns from the function with the results (making the
>function appear synchronous to the caller).
Hack is exactly the right word to describe this. The only way to implement this is by going behind Twisted's back, using unsupported APIs, and risking having the whole thing fall apart in the next point release (that's assuming you get it to work reliably at all, which is a long shot at best).
I recommend working very hard to eliminate this style of usage from your code, and not introducing any further instances of it.
More information about the Twisted-Python