Re: socket setdefaulttimeout
Sheila King wrote:
> I'm doing DNS lookups [...] it is important to make sure
> that the socket doesn't just hang there waiting for a response.
>
> After a recent system upgrade to Python 2.4.1 (from 2.2.2) I thought I
> could take advantage of the setdefaulttimeout in the socket module, to
> limit the amount of time the sockets take for a lookup.
>
> As a test, I set the default timout ridiculously low. But it doesn't
> seem to be having any effect.
The timeout applies to network communication on that socket, but
not to calls such as socket.gethostbyname. The gethostbyname
function actually goes to the operating system, which can look
up the name in a cache, or a hosts file, or query DNS servers
on sockets of its own.
Modern OS's generally have reasonably TCP/IP implementations,
and the OS will handle applying a reasonable timeout. Still
gethostbyname and its brethren can be a pain for single-
threaded event-driven programs, because they can block for
significant time.
Under some older threading systems, any system call would block
every thread in the process, and gethostbyname was notorious for
holding things up. Some systems offer an asynchronous
gethostbyname, but that doesn't help users of Python's library.
Some programmers would keep around a few extra processes to
handle their hosts lookups. Fortunately, threading systems are
now much better, and should only block the thread waiting for
gethostbyname.
--
--Bryan
.
Relevant Pages
- Re: socket setdefaulttimeout
... >> doesn't just hang there waiting for a response. ... >> could take advantage of the setdefaulttimeout in the socket module, ... The gethostbyname function actually ... But we are running this script on ... (comp.lang.python) - Re: UDP performance.
... issue - it has traditionally been the source of statements like "FreeBSD's threading implementation is weak/bad/broken". ... And these days ISC can't consciously recommend FreeBSD for use on high-traffic DNS servers because UDP performance has gone downhill since 5.x. ... Dinesh> affect voip applications/servers such as asterisk when run on ... One of the problems ISC diagnosed had to do with the highly unusual workload pattern of UDP: many different threads simultaneously sending using a single socket leading to unnecessary socket buffer contention. ... (freebsd-performance) - socket setdefaulttimeout
... I'm doing DNS lookups on common spam blacklists (such as SpamCop..and ... others) in an email filtering script. ... that the socket doesn't just hang there waiting for a response. ... (comp.lang.python) - Re: Multi-threading with multi-port server
... Can I ask your guidance on how to imeplement server with multi- ... threading and multi-port? ... If you use asynchronous sockets then all socket calls return quickly and you can run several sockets concurrently in the main thread. ... (microsoft.public.vc.mfc) - Simple UDP server
... I am wondering between Forking, Threading ... and the one describes at the snippet below. ... from socket import * ... (comp.lang.python) |
|