[Tutor] simple threads program

Jeff Shannon jeff@ccvcorp.com
Fri Jul 18 12:42:15 2003


Andreas Zwinkau wrote:

>>You shouldn't really use the thread module unless you have a good
>>reason to.  Use threading instead.
>>    
>>
>What's the difference?
>threading.start_new_thread() is also available, may i use this?
>Any good tutorials/examples?
>

The difference is the threading.Thread class, which handles most of the 
low-level thread management work for you.  Multithreading using 
threading.Threads is typically a matter of creating a subclass of Thread 
which has a run() function that does your work, creating an instance of 
that subclass, and calling that instance's start() method.  You  should 
also look into using Queue.Queue for any inter-thread communication. 
 Queues are a dead-simple and thread-safe way to pass data back and 
forth.  Read the docstrings in the threading and Queue modules for a 
little more detail.

Jeff Shannon
Technician/Programmer
Credit International