Question: Threading and embedding python in an application

Mike Meyer mwm at mired.org
Tue May 10 15:48:36 EDT 2005


David Harrison <daha at best.com> writes:

> I am working on an application on Mac OS X that calls out
> to python via PyImport_ImportModule().  I find that if
> the imported module creates and starts a python thread,
> the thread seems to be killed when the import of
> the module is complete.   Is this expected?  Does
> python have to be in control to allow threads to run?

Having an imported module create a thread is a bad idea. For one
thing, the thread won't get created if the module is imported a second
time. While this may be the desired behavior, it can also be
surprising. For another, there are known behaviors in the Python
threading code that can cause deadlocks when you do this. I say
"behaviors" instead of "bugs", because the last time this came up,
there was no indication that anyone was interested in fixing this.

      <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list