repeat something in a thread, but stop when the program stops

Harald Massa cpl.19.ghum at spamgourmet.com
Wed Sep 29 04:42:08 EDT 2004


Tim,

> as them getting many, the computer begins to feel more sluggish.

> Those are quite different, and they do more work than you may think. 
> For example, if a program puts an icon in the Windows systray, then it
> has a graphical UI too, and has to run a Windows message pump to
> detect stuff like "is the mouse hovering over my icon now?  did they
> click on me?  

My impression from reading dispatcher-code was more in the area of:

a=get_message_from_windows()

if a==waaaah_they_clicked_on_me:
   give_it_to_them_REAL_hard()
elif a==they_hover_over_me:
   do_some_hover_action()

with "get_message_from_windows()" silently and cycle-free blocking until 
windows decides to distribute a message. Something like a blocking 
socket, which makes a program wait.

> A Python thread waking up to see whether a Python Queue has something
> in it does none of that stuff.  If you have hundreds of Python threads
> doing this, then you can start to think about maybe worrying when it
> gets to thousands <wink>.

There was a young monk helping the wise ZEN-master taking a bath. After 
he filled the bath-tub for the master, he had some water left, which he 
poured away. The master got very harsh to him and asked him, who allowed 
him to spill that water.
The young monk got some enlightenment and learned that this is some 
essence of ZEN: to cherish every drop, not to waste anything; and changed 
his name to "drop of water" 

So please excuse my austerity, I also did not know "Queue.get(200)" 
and feared to use:

while True:
    time.sleep(0.5)
    if Queue.empty(): 
       pass
    else
       break

which really takes some Python bytecodes to toast some cycles :))))

Thank you very much for your detailled explanation,

Harald








More information about the Python-list mailing list