From ec3051815c01ca8d98f97cc79747e305fe74abff Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 29 Jun 2018 16:22:21 +0200 Subject: [PATCH] [python] Patch pybind11 function to avoid deadlocks see https://github.com/pybind/pybind11/pull/1211 --- libsrc/general/ngpython.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libsrc/general/ngpython.hpp b/libsrc/general/ngpython.hpp index e0980d85..c3931215 100644 --- a/libsrc/general/ngpython.hpp +++ b/libsrc/general/ngpython.hpp @@ -1,5 +1,17 @@ #ifdef NG_PYTHON +// BEGIN EVIL HACK: Patch PyThread_get_key_value inside pybind11 to avoid deadlocks +// see https://github.com/pybind/pybind11/pull/1211 +#include +#include +namespace pybind11 { + inline void * PyThread_get_key_value(int state) { + PyThreadState *tstate = (PyThreadState *) ::PyThread_get_key_value(state); + if (!tstate) tstate = PyGILState_GetThisThreadState(); + return tstate; + } +} +// END EVIL HACK #include #include namespace py = pybind11;