From 2019f0c9f5a5b5469e65effbd9d70d9ab955e887 Mon Sep 17 00:00:00 2001 From: Felipe Lema Date: Mon, 25 Jan 2016 16:22:44 -0300 Subject: [PATCH] Solves #81 --- include/pybind11/pybind11.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 166966a1c..d99a3ddb0 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -983,13 +983,30 @@ template void implicitly_convertible() ((detail::type_info *) it->second)->implicit_conversions.push_back(implicit_caster); } -inline void init_threading() { PyEval_InitThreads(); } +inline void init_threading() { +#if defined(WITH_THREAD) + PyEval_InitThreads(); +#endif +} class gil_scoped_acquire { +#if defined(WITH_THREAD) PyGILState_STATE state; +#endif public: - inline gil_scoped_acquire() { state = PyGILState_Ensure(); } - inline ~gil_scoped_acquire() { PyGILState_Release(state); } + inline gil_scoped_acquire() { +#if defined(WITH_THREAD) + state = PyGILState_Ensure(); +#endif + } + inline ~gil_scoped_acquire() { +#if defined(WITH_THREAD) + PyGILState_Release(state); +#endif + } +#if defined(WITH_THREAD) + PyEval_InitThreads(); +#endif }; class gil_scoped_release {