[Twisted-Python] Issue with calling back deferreds from threads
Ken Kinder
ken at kenkinder.com
Thu Jul 15 08:22:24 MDT 2004
Andrew Bennetts wrote:
>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
> reactor.installResolver(client.theResolver)
>
>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=[('127.0.0.1', 53)])
> reactor.installResolver(resolver)
>
>There's also a ThreadedResolver, which just uses Python's builtin
>socket.gethostbyname in a thread. You could install that one with:
>
> reactor.installResolver(client.ThreadedResolver())
>
>
Ah -- I wasn't aware of a non-blocking DNS client. I'll give that a
shot, thanks.
If all else fails, I suppose I could wrap my deferred in a list, but I
have to take a shower just thinking about it.
-k
More information about the Twisted-Python
mailing list