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

matt matt at virtualspectator.com
Tue Oct 3 06:16:37 EDT 2000


Using select with a timeout of NULL(None) is the nicer way to do things, i.e.
make select blocking.  It means this thread doesn't have to be limited to just
that socket.  It obviously becomes a lot more useful.


On Tue, 03 Oct 2000, Paul Robinson wrote:
> Joshua Muskovitz wrote:
> > 
> > Hi all,
> > 
> > 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. 
> 
> I've read the other replies about using select and asnycore - but (and
> this question is posed to hopefully enlighten myself as much as anyone
> else), why can't you just make the socket blocking?
> 	
> 	Paul.
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list