python threads: newbie question
Lonnie Princehouse
fnord at u.washington.edu
Thu May 8 13:26:58 EDT 2003
It's pretty easy to start a thread that performs a task
every few seconds with the threading.Thread class.
See http://www.python.org/doc/lib/thread-objects.html
Here's a very basic example:
import threading, time
def thread_loop():
while(1):
# do your mouse/parallel port polling here
time.sleep(5.0) # sleep for the requisite interval
poll_thread = threading.Thread(None, thread_loop)
poll_thread.setDaemon(1) # Without this, your program will hang on exit
poll_thread.start()
# ... and continue with the rest of your program
More information about the Python-list
mailing list