Fix Segfault when jupyter is not installed

This commit is contained in:
Florian Märkl 2019-02-21 19:16:28 +01:00
parent 3cdc6a5230
commit 5313017c54

View File

@ -109,20 +109,23 @@ QVariant JupyterConnection::pollNestedIPyKernel(long id)
bool JupyterConnection::startJupyterNotebook() bool JupyterConnection::startJupyterNotebook()
{ {
Python()->restoreThread(); PythonManager::ThreadHolder threadHolder;
if (!cutterJupyterModule) { if (!cutterJupyterModule) {
cutterJupyterModule = QtResImport("cutter_jupyter"); cutterJupyterModule = QtResImport("cutter_jupyter");
if (!cutterJupyterModule) {
qWarning() << "Failed to load cutter_jupyter module. Make sure jupyter is installed.";
return false;
}
} }
PyObject* startFunc = PyObject_GetAttrString(cutterJupyterModule, "start_jupyter"); PyObject *startFunc = PyObject_GetAttrString(cutterJupyterModule, "start_jupyter");
if (!startFunc) { if (!startFunc) {
qWarning() << "Couldn't get attribute start_jupyter."; qWarning() << "Couldn't get attribute start_jupyter.";
return false; return false;
} }
cutterNotebookAppInstance = PyObject_CallObject(startFunc, nullptr); cutterNotebookAppInstance = PyObject_CallObject(startFunc, nullptr);
Python()->saveThread();
return cutterNotebookAppInstance != nullptr; return cutterNotebookAppInstance != nullptr;
} }