re-entrant call to PyEval_RestoreThread(context) hangs
Greg Chapman
glc at well.com
Sat Feb 28 10:02:29 EST 2004
On 26 Feb 2004 03:54:42 -0800, pcaffrey at iel.ie (Paul) wrote:
>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);
}
---
Greg Chapman
More information about the Python-list
mailing list