Skip to content

Commit f8ff4de

Browse files
committed
[python] Patch pybind11 function to avoid deadlocks
see pybind/pybind11#1211
1 parent 8b3397d commit f8ff4de

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libsrc/core/python_core.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
#pragma clang diagnostic ignored "-Wunused-value"
1111
#endif
1212

13+
// BEGIN EVIL HACK: Patch PyThread_get_key_value inside pybind11 to avoid deadlocks
14+
// see https://github.com/pybind/pybind11/pull/1211
15+
#include <Python.h>
16+
#include <pythread.h>
17+
namespace pybind11 {
18+
inline void * PyThread_get_key_value(int state) {
19+
PyThreadState *tstate = (PyThreadState *) ::PyThread_get_key_value(state);
20+
if (!tstate) tstate = PyGILState_GetThisThreadState();
21+
return tstate;
22+
}
23+
}
24+
// END EVIL HACK
1325
#include <pybind11/pybind11.h>
1426
#include <pybind11/eval.h>
1527
#include <pybind11/operators.h>

0 commit comments

Comments
 (0)