[Twisted-Python] Issue with calling back deferreds from threads

Ken Kinder ken at kenkinder.com
Wed Jul 14 18:27:43 EDT 2004

Introduced in one of the recent versions of Twisted was a patch 
described here. I'm cc'ing itamar because he created the patch:


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)

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.

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.



More information about the Twisted-Python mailing list