Mixing Python and C threads

Stéphane Larouche stephane.larouche at polymtl.ca
Fri Jul 6 13:51:15 EDT 2007


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?

Thank you for the quick answer.

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.

Am I missing something?




More information about the Python-list mailing list