how do I listen on a socket without sucking up all the CPU time?

Grant Edwards ge at nowhere.none
Tue Oct 3 08:19:58 EDT 2000


In article <39d971f3_1 at corp.newsfeeds.com>, Joshua Muskovitz wrote:

>I've got a worker thread which listens on an ICMP (ping) socket for replies
>to pings that I send out (on the same socket from a different thread).  All
>of this code runs fine, but the socket is set to be non-blocking, so
>recvfrom() returns immediately most of the time, and this thread runs like
>mad, consuming all the available CPU time. 

Why is the socket set to non-blocking?  Why not set it to
blocking so that the thread blocks until there's data to read?

-- 
Grant Edwards                   grante             Yow!  Th' MIND is the Pizza
                                  at               Palace of th' SOUL
                               visi.com            



More information about the Python-list mailing list