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

Tim Peters tim.peters at gmail.com
Tue Sep 28 18:41:03 CEST 2004


[Tim Peters, on waking up a thread to check a queue 20 times a second]
>> Measure it:  you won't be able to see a difference.  Modern processors
>> cram on the order of 1E9 cycles into each second.  Doing a tiny amount
>> of work 20 times per second is trivial.

[Harald Massa]
> You are surely right, Tim. Measuring did not detect the difference. I just
> see my tasktray collecting more and more icons of programs which just do a
> very tiny amount of work every half a second, and ... 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?  did they right-click on me?  did they double-click on
me?".  Apps in the systray often do a lot more than just that too. 
For example, one app in my systray right now hooks itself into the
Windows clipboard chain, and intercepts (and so also slows, by some
amount I couldn't care less about) all clipboard operations.  Another
hooks itself into the file system at a low level, tracking all disk
changes, and so slows (by a measurable amount!) all disk writes. 
Heck, the little systray icon showing the pressure on my laptop's
touchpad represents a process that has read over a billion bytes since
I last booted.  Etc.

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>.



More information about the Python-list mailing list