python threading

Peter Hansen peter at engcorp.com
Tue Apr 16 02:23:07 EDT 2002


sameer wrote:
> 
> I am trying to run multiple threads in a wxFrame class to instantiate
> different panels within it on Win 2k,  and well, it's a little hairy.
> Anyone got a good web source that discusses python threading in depth?

Sorry, not handy.  Maybe others can help.

> More so, my question is, how can I get the return value of a function
> that I run on a seperate thread?  I don't see anything for this in the
> threading module.

Threads don't "return" in the sense of going back to the routine
which called them.  They are spun off at the time they are started,
largely independent of their creator.

You might look into the join() method of the threading.Thread class,
which you could use in a calling routine to wait for termination
of a thread (but if you do that in the wxPython mainloop, you'll
freeze the GUI).

For actually passing a value, you can just store something as
an attribute of the Thread object, and retrieve it after the
thread has terminated, if you keep a reference to the thread
in the creator.

Threads are not trivial, especially when mixed with GUI stuff.
Search the web for examples.  Try google with something like
http://www.google.com/search?q=wxpython+threading+thread+python+examples

-Peter



More information about the Python-list mailing list