how do I listen on a socket without sucking up all the CPU time?
Mike 'Cat' Perkonigg
blablu at gmx.net
Wed Oct 4 05:55:28 EDT 2000
donn at oz.net (Donn Cave) wrote in <8reb7f$gk6$0 at 216.39.151.169>:
>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
>
I have some threads which are just looking if a queue is filled. So the
main loop of these threads consist of:
while runFlag:
if inQueue.empty() == 0:
doSomething...
I could do:
while runFlag:
inData = inQueue.get(1)
doSomething...
but if I do that I can't check runFlag most of the time.
My main understanding problem is now, what I have to do if I want to check
this queue every 10 seconds without blocking other threads.
Can I use time.sleep(10) as a timer or will that block the thread
switching?
Regards,
Mike
More information about the Python-list
mailing list