idle tasks

Gordon McMillan gmcm at hypernet.com
Tue Jun 15 13:58:01 EDT 1999


Nathan Clegg writes:

> I'm writing a multi-threaded application with the threading module. 
> I would like one of the threads to run as the lowest priority,
> effectively an idle function.  I typically only see idle functions
> in GUI toolkits, however, and this needs to be a console app.  Is
> there a way to lower the priority of a thread or create an idle
> function without using tkinter or pygtk??

A GUI's "idle" function is usually run from the GUI's thread when it 
finds that there hasn't been a GUI event in awhile. So your function 
needs to only do small snippets of work, or it will block the GUI.

No priorities on Python threads. You might just put in plenty of 
small sleep()s, which will ensure that other threads get plenty of 
chances to run. But since the PVM swaps threadstates every 10 (unless 
you've fiddled with it) byte code instructions, you probably don't 
need it.


- Gordon




More information about the Python-list mailing list