473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Reentrancy of Python interpreter

I have embedded a single threaded instance of the Python interpreter in my
application.

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."

I guess I understand why I can't have two invocations of the same interpreter
thread in one call stack, but how would I go about solving this?

Sep 28 '07 #1
4 2296
On Sep 28, 11:31 pm, Brad Johnson <Brad.John...@ballardtech.com>
wrote:
I have embedded a single threaded instance of the Python interpreter in my
application.

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."

I guess I understand why I can't have two invocations of the same interpreter
thread in one call stack, but how would I go about solving this?
Looks like ( from PyThreadStage_Get error ) that you lost the GIL. You
probably
entered some C++ code and encapsulated you're work in the

Py_BEGIN_ALLOW_THREADS
<code>
Py_END_ALLOW_THREADS

but you're <codeis calling back the Python function, and you forgot
to acquire
back the GIL.

Sep 29 '07 #2
<bvukov <atyahoo.comwrites:
Looks like ( from PyThreadStage_Get error ) that you lost the GIL. You
probably
entered some C++ code and encapsulated you're work in the

Py_BEGIN_ALLOW_THREADS
<code>
Py_END_ALLOW_THREADS

but you're <codeis calling back the Python function, and you forgot
to acquire
back the GIL.
I didn't explicitly allow for threads in Python. It should just be single
threaded. So I don't understand why I should have to acquire the GIL for the
second call into the interpreter, or how I lost the GIL in the first place.

Maybe I just need the second call to be placed into its own thread...?
Oct 1 '07 #3
Brad Johnson <Br**********@ballardtech.comwrites:
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?
Oct 1 '07 #4
Hrvoje Niksic <hniksic <atxemacs.orgwrites:
>
Brad Johnson <Brad.Johnson <atballardtech.comwrites:
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.

Oct 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: vincent Salaun | last post by:
hi all, here's my problem : I've embedded a python interpreter in our java application (based on the NetBeans palteforrm) using the Jython API : http://www.jython.org/docs/javadoc/index.html...
12
by: Anon | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all I am a beginner teaching myself python, and I am enjoying it immensely :) As a language it is great, I real treat to study, I actually...
3
by: XPhaktor | last post by:
In C#, how do I replace using VB local static variable declarations to handle method reentrancy. Note, if you use a class-scope variable instead of a local one, then you run the risk of...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
1
by: Petr Prikryl | last post by:
Do you think that the following could became PEP (pre PEP). Please, read it, comment it, reformulate it,... Abstract Introduction of the mechanism for language extensions via modules...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
5
by: Adam Atlas | last post by:
Does anyone know if it would be possible to create a CPython extension -- or use the ctypes module -- to access Python's own embedding API (http://docs.python.org/api/initialization.html &c.)?...
3
by: Marcin Kalicinski | last post by:
How do I use multiple Python interpreters within the same process? I know there's a function Py_NewInterpreter. However, how do I use functions like Py_RunString etc. with it? They don't take any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.