[Twisted-Python] Twisted names client.getHostbyName dual-stack operation

Glyph glyph at twistedmatrix.com
Mon Jan 6 02:03:34 MST 2014


On Jan 6, 2014, at 12:26 AM, Maciej Wasilak <wasilak at gmail.com> wrote:

> After Twisted 13.2 announcement I've checked the new HostnameEndpoint implementation to find possible solution (it seems to be dedicated to solve similar problems, but for TCP-based protocols). However it seems to use deferToThread(), and built-in Python getaddrinfo().

Sadly, the algorithm HostnameEndpoint uses to determine which host to actually send traffic to depends on TCP connection establishment; if you're doing UDP you're on your own with this.

> My questions:
> 1. Is using deferToThread() a preferred solution?

You kinda have to use it.  getaddrinfo is actually standardized in an RFC, and that RFC defines no asynchronous version of this API.  So if you want proper 6-or-4 behavior, deferToThread(getaddrinfo) is about as well as you can do for the general case.

(Now, in specific cases you can use the twisted.names DNS client and avoid the trip out to your operating system and also out to a thread, but this is for somewhat specialized configurations, only if the getaddrinfo approach is not scaling for you.)

-glyph




More information about the Twisted-Python mailing list