Reentrancy of Python interpreter

Brad Johnson Brad.Johnson at ballardtech.com
Mon Oct 1 20:11:01 EDT 2007


Hrvoje Niksic <hniksic <at> xemacs.org> writes:

> 
> Brad Johnson <Brad.Johnson <at> ballardtech.com> writes:
> 
> > I have a place where I execute a Python command that calls into C++
> > code which then in turn calls back into Python using the same
> > interpreter. I get a fatal error which is "PyThreadStage_Get: no
> > current thread."
> 
> Does the C++ code call into the interpreter from a different thread?

No.

But, problem has been solved. I enabled thread support for the Python
interpreter and now wrap the code that caused the problem in PyGILState_Ensure
and PyGILState_Release. I'm not sure why this fixed it. My theory is that the
Python interpreter is not reentrant and requires another thread if you call into
it more than once in the same call chain.




More information about the Python-list mailing list