Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix RuntimeError: pybind11::handle::inc_ref() PyGILState_Check() failure.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 5 Jun 2023 12:37:21 +0000 (14:37 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 5 Jun 2023 12:37:21 +0000 (14:37 +0200)
See commit 2c2d94471739d82e9cbd370711f73377e0b17717 for details.

src/bindings/python/simgrid_python.cpp

index a89056d..d0ce338 100644 (file)
@@ -927,9 +927,9 @@ PYBIND11_MODULE(simgrid, m)
           [](py::object cb) {
             cb.inc_ref(); // keep alive after return
             const py::gil_scoped_release gil_release;
-            Task::on_start_cb([cb](Task* op) {
+            Task::on_start_cb([cb_p = cb.ptr()](Task* op) {
               const py::gil_scoped_acquire py_context; // need a new context for callback
-              py::reinterpret_borrow<py::function>(cb.ptr())(op);
+              py::reinterpret_borrow<py::function>(cb_p)(op);
             });
           },
           "Add a callback called when each task starts.")
@@ -938,9 +938,9 @@ PYBIND11_MODULE(simgrid, m)
           [](py::object cb) {
             cb.inc_ref(); // keep alive after return
             const py::gil_scoped_release gil_release;
-            Task::on_end_cb([cb](Task* op) {
+            Task::on_end_cb([cb_p = cb.ptr()](Task* op) {
               const py::gil_scoped_acquire py_context; // need a new context for callback
-              py::reinterpret_borrow<py::function>(cb.ptr())(op);
+              py::reinterpret_borrow<py::function>(cb_p)(op);
             });
           },
           "Add a callback called when each task ends.")