Avoid a deadlock: GIL release in constructor and destructor of threadedindatahandler.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Anne de Jong 2023-06-20 17:08:55 +02:00
parent 2420e6cb28
commit 4ca8866cb7

View File

@ -96,9 +96,9 @@ py::array_t<d> 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<PyIndataHandler> {
/**
@ -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();
}
}
};