From 186ae0146af48a5d5b6fe3956c655482bd7b27c6 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 23 Feb 2024 18:39:25 +0100 Subject: [PATCH] [29576] : management of dump state in separate thread --- src/Basics/PythonCppUtils.hxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Basics/PythonCppUtils.hxx b/src/Basics/PythonCppUtils.hxx index 905005566..8a54b86bb 100644 --- a/src/Basics/PythonCppUtils.hxx +++ b/src/Basics/PythonCppUtils.hxx @@ -34,7 +34,7 @@ class AutoPyRef { public: AutoPyRef(PyObject *pyobj=nullptr):_pyobj(pyobj) { } - virtual ~AutoPyRef() { release(); } + ~AutoPyRef() { release(); } AutoPyRef(const AutoPyRef& other):_pyobj(other._pyobj) { if(_pyobj) Py_XINCREF(_pyobj); } AutoPyRef(AutoPyRef&& other) = default; AutoPyRef& operator=(const AutoPyRef& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; Py_XINCREF(_pyobj); return *this; } @@ -55,3 +55,12 @@ public: AutoPyRefGilSafe(PyObject *pyobj=nullptr):AutoPyRef(pyobj) { } ~AutoPyRefGilSafe() { AutoGIL agil; release(); } }; + +class AutoPyYielder +{ +private: + PyThreadState *_save = nullptr; +public: + AutoPyYielder() { _save = PyEval_SaveThread(); } + ~AutoPyYielder() { PyEval_RestoreThread(_save); } +}; -- 2.39.2