Mixing Python and C threads

Aahz aahz at pythoncraft.com
Sat Jul 7 09:46:29 EDT 2007


In article <mailman.417.1183744293.22759.python-list at python.org>,
=?utf-8?b?U3TDqXBoYW5l?= Larouche  <stephane.larouche at polymtl.ca> wrote:
>Aahz <aahz <at> pythoncraft.com> writes:
>> In article <mailman.412.1183729810.22759.python-list <at> python.org>,
>> =?utf-8?b?U3TDqXBoYW5l?= Larouche  <stephane.larouche <at> polymtl.ca> wrote:
>>>
>>>If I call the methods in the C++ modules from the Python main thread, I
>>>don't have any problem. However, they are usually called from another
>>>Python thread (using the threading module) to keep the GUI responsive
>>>and, then, Python crashes.
>> 
>> The question is whether your C++ code is designed to be called from
>> multiple threads.  That is, if you call your C++ code from a *single*
>> non-main thread, does it work?
>
>It does work if I call it from a single non-main thread. But everything
>must be called from that thread, including the import of the module.
>
>I still do not understand what is the problem. The C++ code is not
>thread safe, but I call it from 1 Python thread at a time. Anyway,
>I have always called it from multiple Python threads without any
>problem. Having put a few printf in the module, I can say that it
>crashes exactly when it tries to create C threads.

Can you reproduce your problem with stub code that only creates threads?
If yes, that indicates that you're messing with a thread structure
somewhere.  Note that because you're using gcc, it's possible there's a
thread bug on Windows with your tool chain.  You might want to check for
bug reports.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

I support the RKAB



More information about the Python-list mailing list