Pregunta

I have a python program that calls into a c++ library, which wishes to release all the python locks so that other python threads can run.

Using PyEval_SaveThread and PyEval_ReleaseThread I get errors that the thread state is NULL:

Fatal Python error: PyEval_SaveThread: NULL tstate

However, the lower-level function seem to accept the NULL state happily:

PyThreadState *s;
s = PyThreadState_Swap(NULL);
// (now s = 0)
PyEval_ReleaseLock();

// ....

PyEval_AcquireLock();
PyThreadState_Swap(s);

// everything seems to be just fine :)
¿Fue útil?

Solución

Answer: no, it is never meant to be NULL (if it is, it's a fatal error). Turned out this was because I was linking against two different versions of python, one via boost_python, and the other directly.

Top Tip: use ldd or otool -L to check your library dependencies when funny stuff happens ;)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top