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

Donn Cave donn at oz.net
Wed Oct 4 00:21:03 EDT 2000


Quoth blablu at gmx.net (Mike 'Cat' Perkonigg):
| There comes another question in mind: Can I somehow tell a thread that there 
| is nothing to do so another thread can consume more time?
| I heard the active thread changes if there are 10 byteOps are done. Does that 
| mean I have just to implement a "while 1: pass" loop to have this thread 
| consume less time?

As another followup has already mentioned, any external function call
that could stall for any time at all will when properly implemented,
release the global interpreter lock.  As soon as you block on a
semaphore or I/O device or anything of that sort, you hit one of
these functions and another thread can go.

This is really a design opportunity, a good time to start thinking
about how a central dispatching facility in your program could
provide something along these lines.

	Donn Cave, donn at oz.net



More information about the Python-list mailing list