From 9434476c116b3a63eba9730ede982e2ecece7202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 27 Feb 2018 16:26:16 +0100 Subject: [PATCH] Fix JupyterConnection Shutdown on Error --- src/utils/JupyterConnection.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/utils/JupyterConnection.cpp b/src/utils/JupyterConnection.cpp index 63d7ff25..173c4b79 100644 --- a/src/utils/JupyterConnection.cpp +++ b/src/utils/JupyterConnection.cpp @@ -25,17 +25,17 @@ JupyterConnection::JupyterConnection(QObject *parent) : QObject(parent) JupyterConnection::~JupyterConnection() { - if (cutterNotebookAppInstance) + if (pyThreadState) { PyEval_RestoreThread(pyThreadState); - auto stopFunc = PyObject_GetAttrString(cutterNotebookAppInstance, "stop"); - PyObject_CallObject(stopFunc, nullptr); - Py_DECREF(cutterNotebookAppInstance); - } + if (cutterNotebookAppInstance) + { + auto stopFunc = PyObject_GetAttrString(cutterNotebookAppInstance, "stop"); + PyObject_CallObject(stopFunc, nullptr); + Py_DECREF(cutterNotebookAppInstance); + } - if (Py_IsInitialized()) - { Py_Finalize(); } } @@ -63,20 +63,22 @@ void JupyterConnection::createCutterJupyterModule() auto moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_jupyter.py", Py_file_input); if (!moduleCodeObject) { + PyErr_Print(); qWarning() << "Could not compile cutter_jupyter."; emit creationFailed(); pyThreadState = PyEval_SaveThread(); return; } cutterJupyterModule = PyImport_ExecCodeModule("cutter_jupyter", moduleCodeObject); - Py_DECREF(moduleCodeObject); if (!cutterJupyterModule) { + PyErr_Print(); qWarning() << "Could not import cutter_jupyter."; emit creationFailed(); pyThreadState = PyEval_SaveThread(); return; } + Py_DECREF(moduleCodeObject); pyThreadState = PyEval_SaveThread(); }