The thread module

The thread module provides low-level access to threads

  • Thread creation.
  • Simple mutex locks.

Creating a new thread

  • thread.start_new_thread(func,[args [,kwargs]])
  • Executes a function in a new thread.
     import thread
     import time
     def print_time(delay):
         while 1:
              time.sleep(delay)
              print time.ctime(time.time())
     
     # Start the thread
     thread.start_new_thread(print_time,(5,))
     # Go do something else
     statements
     ...
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 68
July 17, 2000, beazley@cs.uchicago.edu
>>>