- PySys_SetArgv(argc, argv);
- SUIT_PYTHON::_interp = PyThreadState_Get()->interp;
- PyEval_InitThreads(); // Create (and acquire) the interpreter lock
- SUIT_PYTHON::_gtstate = PyEval_SaveThread(); // Release global thread state
+
+ PySys_SetArgv(argc, changed_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);