Learning to use threads.

Laura Creighton lac at strakt.com
Sat Jan 25 18:57:56 EST 2003


> I've never used threads before and thought now would be a good time to 
> learn. Are there any good sites with tutorials of using threads with 
> Python? I have a project where I think one object creates several 
> threads and each thread returns messages back to the parent object. Is 
> this a good way to do things? Could someone post a small example?
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Check out:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965
and the rest of the threading section in the cookbook.

The 2. most important things to learn are 'Use Queues to communicate between
threads' and 'Don't use the thread module directly.  Use the threading
one instead, which handles all of the nasty details for you'.

Jacob Hallen gave a tutorial on how to use threads at EuroPython last year
(2002).  His tutorial slides are here: 
http://europython.zope.nl/sessions/presentations/

(but be warned this is about to get archived as we prepare for next
 years EuroPython.  If you are reading this via a google search, 
 this was a 2002 talk).

Aahz gave a tutorial at IPC9.  His slides are here.
http://starship.python.net/crew/aahz/IPC9/index.html

The thing to remember is that this is very easy.  Everything you have
ever heard about this being hard is wrong.  It is hard -- if you
aren't using Queues to communicate between threads and if you are
messing around doing your own locking rather than letting the
threading module take care of it.

Happy hacking,
Laura Creighton





More information about the Python-list mailing list