Python Threading

Bryan Olson fakeaddress at nowhere.org
Fri Sep 22 16:34:12 EDT 2006


daniel wrote:
> Can anyone explain the main points in working with threads in Python.

They are system threads, so the main points are much like in
other languages. Examine how thread.lock works, and look up the
queue module.

> Why use threading and not Thread.

There's no reason not to use thread, but threading adds
some useful items, such as setDaemon(), condition variables,
semaphores, and maybe rlocks. Try to avoid using the timeout
argument on condition variables if efficiency matters; Event and
queue.queue are implemented on top of condition variables, so
same deal.

> I have read an article that i have to
> subclass the Thread class and override some function.

You can, but that's the hard way. The following snippet runs
func(arg1, arg2) in a daemon thread:

       import threading
       # ...

       t = threading.Thread(target=func, args=(arg1, arg2))
       t.setDaemon(True)
       t.start()


-- 
--Bryan



More information about the Python-list mailing list