On Apr 23, 2:16 pm, Piet van Oostrum <p...@cs.uu.nl> wrote: > >>>>> marc wyburn <marc.wyb...@googlemail.com> (MW) wrote: > >MW> Hi, I am writing anasynchronousping 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.gethostbynameif 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 fromgethostbyname. And an additional thread which gets from the > first queue, callsgethostbynameand 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 <p...@cs.uu.nl> > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p...@vanoostrum.org
Hi, I did try this but the socket blocked for so long that this was a real bottleneck. It also seemed that whilst the DNS lookup thread was blocking the other threads were also blocked. I guess this may have something to do with the GIL but I'm still fairly new to threading. I ended up using DNSPython which flys along. I have a thread creating the ping packets and pinging them and another performing a select and logging + filtering any ICMP replies. I may put the DNS code into another thread but the whole script runs faster than I need it to as it is, I've got time.sleeps in the ping thread as I'm scared of saturating the local LAN during work hours. -- http://mail.python.org/mailman/listinfo/python-list