gethostbyname blocking

Piet van Oostrum piet at cs.uu.nl
Thu Apr 23 15:16:56 CEST 2009


>>>>> marc wyburn <marc.wyburn at googlemail.com> (MW) wrote:

>MW> Hi, I am writing an asynchronous ping app to check if 1000s of hosts
>MW> are alive very quickly.  Everything works extremely quickly unless the
>MW> host name doesn't have a DNS record.

>MW> when calling socket.gethostbyname if there is no record for the host
>MW> the result seems to block all other threads.  As an example I have 6
>MW> threads running and if I pass the class below a Queue with about 30
>MW> valid addresses with one invalid address in the middle the thread that
>MW> the exception occurs in seems to block the others.

What you could do is have two Queues, one with host names, and one with
results from gethostbyname. And an additional thread which gets from the
first queue, calls gethostbyname and puts the results in the second queue.
The ping threads then should get from the second queue. The lookup
thread could even do caching of the results if you often have to repeat
the pings for thew same host.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list