[Twisted-Python] Issue with calling back deferreds from threads
Bob Ippolito
bob at redivi.com
Wed Jul 14 19:26:13 EDT 2004
On Jul 14, 2004, at 6:27 PM, Ken Kinder wrote:
> Introduced in one of the recent versions of Twisted was a patch
> described here. I'm cc'ing itamar because he created the patch:
>
>
> http://twistedmatrix.com/pipermail/twisted-commits/2003-November/
> 010059.html
>
> This makes sure you can't callback with Deferred objects. However,
> some of my code depends on doing just that because of the blocking DNS
> issue:
>
> def mymethod(*args):
> def go(*args):
> return xmlproxy.callRemote(*args)
> twisted.internet.threads.deferToThread(go)
>
> As you can see, I'm deferring something that should not be blocking to
> a thread. The purpose for doing so is that sometimes resolving the
> hostname can take a while for this call. (Unrelated document issue
> with Twisted: DNS is blocking.) So, in this case, it is desirable
> (although hackish) to defer the creation of a deferred object to a
> thread, and itamar's patch prevents this process.
Isn't there a quick way to turn on Twisted's DNS client, so that DNS is
non-blocking?
> One option I have is to make go() blocking, but that will hold a
> thread open for longer than is necessary. Another option is to comment
> out the assertion, but that's probably not a good idea. Until the DNS
> blocking issue is resolved, I'm not sure how to solve this one.
>
> Suggestions?
Yeah, use reactor.callFromThread.
-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040714/0ca7625f/attachment-0001.bin
More information about the Twisted-Python
mailing list