diff --git a/src/lasp/pybind11/lasp_pyindatahandler.cpp b/src/lasp/pybind11/lasp_pyindatahandler.cpp index cf4406b..1a366b7 100644 --- a/src/lasp/pybind11/lasp_pyindatahandler.cpp +++ b/src/lasp/pybind11/lasp_pyindatahandler.cpp @@ -96,9 +96,9 @@ py::array_t dmat_to_ndarray(const DaqData &d) { } /** - * @brief Wraps the ThreadedInDataHandler such that it calls a Python callback with a - * buffer of sample data. Converts DaqData objects to Numpy arrays and calls - * Python given as argument to the constructor + * @brief Wraps the ThreadedInDataHandler such that it calls a Python callback + * with a buffer of sample data. Converts DaqData objects to Numpy arrays and + * calls Python given as argument to the constructor */ class PyIndataHandler : public ThreadedInDataHandler { /** @@ -122,10 +122,14 @@ public: DEBUGTRACE_ENTER; /// Start should be called externally, as at constructor time no virtual /// functions should be called. + py::gil_scoped_release release; startThread(); } ~PyIndataHandler() { DEBUGTRACE_ENTER; + /// Callback cannot be called, which results in a deadlock on the GIL + /// without this release. + py::gil_scoped_release release; stopThread(); } /** @@ -163,8 +167,8 @@ public: using DataType = DataTypeDescriptor::DataType; - py::gil_scoped_acquire acquire; try { + py::gil_scoped_acquire acquire; py::object bool_val; switch (d.dtype) { case (DataType::dtype_int8): { @@ -195,6 +199,9 @@ public: cerr << e.what() << endl; cerr << "ERROR: Python callback does not return boolean value." << endl; abort(); + } catch (std::exception &e) { + cerr << "Caught unknown exception:" << e.what() << endl; + abort(); } } };