From: Anthony Geay Date: Fri, 23 Feb 2024 17:39:25 +0000 (+0100) Subject: [29576] : management of dump state in separate thread X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=186ae0146af48a5d5b6fe3956c655482bd7b27c6;p=modules%2Fkernel.git [29576] : management of dump state in separate thread --- 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); } +};