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

Andrew Bennetts andrew-twisted at puzzling.org
Thu Jul 15 01:33:05 EDT 2004

On Wed, Jul 14, 2004 at 07:26:13PM -0400, Bob Ippolito wrote:
> On Jul 14, 2004, at 6:27 PM, Ken Kinder wrote:
> >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?

There is, although not clearly documented anywhere I know of.  It's:

    from twisted.names import client
    from twisted.internet import reactor

If you need a resolver with different behavior to the default (e.g. you want
to tell it to use a specific DNS server), use:

    resolver = client.createResolver(servers=[('', 53)])

There's also a ThreadedResolver, which just uses Python's builtin
socket.gethostbyname in a thread.  You could install that one with:



More information about the Twisted-Python mailing list