From 9d131e5d28c4a6b06886b12a04b5ff11e4fc3653 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 22 Sep 2016 10:05:42 +0300 Subject: [PATCH] 0023354: EDF 13548 EFICAS: Salome crash --- src/SUITApp/SUITApp_init_python.cxx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/SUITApp/SUITApp_init_python.cxx b/src/SUITApp/SUITApp_init_python.cxx index bfbe0f217..372d3e6ed 100644 --- a/src/SUITApp/SUITApp_init_python.cxx +++ b/src/SUITApp/SUITApp_init_python.cxx @@ -17,12 +17,11 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) -// Date : 22/06/2007 -// + #include "SUITApp_init_python.hxx" +#include -bool SUIT_PYTHON::initialized = false; +bool SUIT_PYTHON::initialized = false; void SUIT_PYTHON::init_python(int argc, char **argv) { @@ -33,11 +32,23 @@ void SUIT_PYTHON::init_python(int argc, char **argv) Py_SetProgramName(argv[0]); Py_Initialize(); // Initialize the interpreter PySys_SetArgv(argc, argv); + PyRun_SimpleString("import threading\n"); + // VSR (22/09/2016): This is a workaround to prevent invoking qFatal() from PyQt5 + // causing application aborting + QString script; + script += "def _custom_except_hook(exc_type, exc_value, exc_traceback):\n"; + script += " import sys\n"; + script += " sys.__excepthook__(exc_type, exc_value, exc_traceback)\n"; + script += " pass\n"; + script += "\n"; + script += "import sys\n"; + script += "sys.excepthook = _custom_except_hook\n"; + script += "del _custom_except_hook, sys\n"; + int res = PyRun_SimpleString(qPrintable(script)); + // VSR (22/09/2016): end of workaround PyEval_InitThreads(); // Create (and acquire) the interpreter lock - can be called many times - // Py_InitThreads acquires the GIL PyThreadState *pts = PyGILState_GetThisThreadState(); PyEval_ReleaseThread(pts); SUIT_PYTHON::initialized = true; } - -- 2.39.2