Python threading

From Noah.org
Revision as of 18:00, 3 January 2008 by Root (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Basic threading example

This is a simple example of threading in Python. You pass it any function and your function is run in a thread loop.

Click to download: thread_looper.py <include svncat src="file:///home/svn/src/python/thread_looper.py" highlight="python" />

Example output:

Calling my_function() in a thread every 1/10th of second for two seconds.
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:33 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:34 2007
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:35 2007
Done!
meaningless arguments as an example: 1 0 -1
Thu Jun  7 13:34:35 2007