re-entrant call to PyEval_RestoreThread(context) hangs

P

Paul

following hangs when re-entered

run()
{
PyEval_RestoreThread(context);

pName = PyString_FromString(script);

Py_DECREF(pName);

context = PyEval_SaveThread();
}

This invokes a python script (using context[0])

The python script uses "swig" to call back into the run() method
The run() method now calls PyEval_RestoreThread(context[1])

but this hangs

ie to summarise

C++ run() context0
-> .py
-> C++ run() context1 HANGS!

Can anyone suggest a solution for this?
 
G

Greg Chapman

following hangs when re-entered

run()
{
PyEval_RestoreThread(context);

pName = PyString_FromString(script);

Py_DECREF(pName);

context = PyEval_SaveThread();
}

This invokes a python script (using context[0])

The python script uses "swig" to call back into the run() method
The run() method now calls PyEval_RestoreThread(context[1])

but this hangs

ie to summarise

C++ run() context0
-> .py
-> C++ run() context1 HANGS!

Can anyone suggest a solution for this?

I've never used SWIG, so I'm not sure if your run method is something for which
SWIG generates the actual C code or pseudocode you're using for example.
Anyway, if you're using 2.3, you can use the PyGILState API:

run()
{
PyGILState_STATE state = PyGILState_Ensure();

PyObject *pName = PyString_FromString(script);

Py_XDECREF(pName);

PyGILState_Release(state);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top