From 6191a5aa83d752952c51adec60881813316a62c9 Mon Sep 17 00:00:00 2001 From: Rob Ambalu Date: Thu, 4 Jun 2026 17:03:06 -0400 Subject: [PATCH] Added a PyErr_CheckSignals() call every time we re-aquire the GIL. this is to ensure we process any pending signals even if not calling into python. Also have PyEngine return NULL if there is a pending exception ( ie KeyboardInterrupt ) so that it gets raised on return Signed-off-by: Rob Ambalu --- cpp/csp/python/PyEngine.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpp/csp/python/PyEngine.cpp b/cpp/csp/python/PyEngine.cpp index e6f90de0e..1689fa364 100644 --- a/cpp/csp/python/PyEngine.cpp +++ b/cpp/csp/python/PyEngine.cpp @@ -31,6 +31,8 @@ void PythonEngine::dialectLockGIL() noexcept { PyEval_RestoreThread( m_pyThreadState ); m_pyThreadState = nullptr; + if( PyErr_CheckSignals() == -1 && PyErr_Occurred() ) + shutdown(); } //The engine python wrapper object @@ -114,7 +116,7 @@ static PyObject * PyEngine_run( PyEngine * self, PyObject * args ) CSP_TRUE_OR_THROW_RUNTIME( self -> engine() -> isRootEngine(), "engine is not root engine" ); self -> rootEngine() -> run( start, end ); - return self -> collectOutputs(); + return PyErr_Occurred() ? nullptr : self -> collectOutputs(); CSP_RETURN_NONE; }