Skip to content

Commit ec30518

Browse files
committed
[python] Patch pybind11 function to avoid deadlocks
see pybind/pybind11#1211
1 parent 95efdd2 commit ec30518

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libsrc/general/ngpython.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#ifdef NG_PYTHON
22

3+
// BEGIN EVIL HACK: Patch PyThread_get_key_value inside pybind11 to avoid deadlocks
4+
// see https://github.com/pybind/pybind11/pull/1211
5+
#include <Python.h>
6+
#include <pythread.h>
7+
namespace pybind11 {
8+
inline void * PyThread_get_key_value(int state) {
9+
PyThreadState *tstate = (PyThreadState *) ::PyThread_get_key_value(state);
10+
if (!tstate) tstate = PyGILState_GetThisThreadState();
11+
return tstate;
12+
}
13+
}
14+
// END EVIL HACK
315
#include <pybind11/pybind11.h>
416
#include <pybind11/operators.h>
517
namespace py = pybind11;

0 commit comments

Comments
 (0)