From de4865b3241ded61a88d0501b8dfeac2d1052b31 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 28 Jul 2025 10:01:11 +0200 Subject: [PATCH] putil: grab GIL while decreffing function --- panda/src/putil/pythonCallbackObject.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/panda/src/putil/pythonCallbackObject.cxx b/panda/src/putil/pythonCallbackObject.cxx index 3e185e8514..3841abcb9d 100644 --- a/panda/src/putil/pythonCallbackObject.cxx +++ b/panda/src/putil/pythonCallbackObject.cxx @@ -60,7 +60,18 @@ PythonCallbackObject(PyObject *function) { */ PythonCallbackObject:: ~PythonCallbackObject() { + // This may be called from the cull or draw thread, so we have to be sure we + // own the GIL. +#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); +#endif + Py_DECREF(_function); + +#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) + PyGILState_Release(gstate); +#endif } /**