The TaskThread class allows you to create threads that execute a specific action at a specified interval, by subclassing - just override the task() method. You can also shutdown a TaskThread without having to wait for it to finish "sleeping" (due to the use of threading.Event objects as an alternative to time.sleep()).
Python, 30 lines
In a lot of cases we want a thread to do something every few seconds, for example an email program may want to check if there is new mail on the POP3 server. Using TaskThread we can create classes for specific tasks - this is a great way to work with threads in general.
I know that wxPython has a wxTimer class that does the same thing, presumably using wxWindows event loop instead of threads, and there may be other ways of doing this as well.