how to start a new thread from a GUI

Brian Kelley bkelley at wi.mit.edu
Thu Aug 16 17:18:11 EDT 2001


Donn Cave wrote:

>Quoth Brian Kelley <bkelley at wi.mit.edu>:
>...
>| Also be aware that whenever you use python's thread package with a
>| purely python written program you will see slowdowns in the workers you
>| are running. We have seen up to 30% speed loss between a threaded
>| process and an unthreaded process. If speed is an issue you can set up
>| the worker to run in a seperate python process and use pipes/sockets for
>| update and control events. Python makes this fairly easy to do, although
>| whenever you touch pipes/sockets you are getting into the realm of
>| techno-weenie. Let me know if you need advice on this, we are trying to
>| release some code to facilitate linux and windows out of process
>| asynchrounous communication, but don't hold your breath.
>
>Lose 30%??!!  Where does it go, do you have any idea?
>
>	Donn Cave, donn at u.washington.edu
>
Python has a global lock during threading so that only one python 
instruction can be running at a time.  If you GUI runs a lot of python 
calls and your threaded process runs a lot of python calls. 
 Bingo---you're hosed.

Fortunately running components in other processes is relatively easy. 
 There are a lot of remote proxies running around out there.  The main 
problem is asynchronous I/O because not only do you have to connect to 
the operating systems I/O you have to work into the GUI systems I/O and 
event loop.  Gtk/Tk/Qt and wxPython allow for fairly easy hooks into 
their event loop so you can poll sockets/pipes with a simple callback or 
timer mechanism(which of course is GUI specific).  Even COM and CORBA 
have to deal with this reality.  If you care to dig deeper you can check 
out the execellent fnorb (python corba orb) documentation for working 
with GUI event loops.

This kind of thing really gets hard for novices incredibly quickly, it 
quite literally is a big old brick wall for a lot of people.  Hopefully 
we'll be able to fix it one day :)

Brian Kelley
Whitehead Institute for Biomedical Research




More information about the Python-list mailing list