From 8abf4de916bda5985c9b4713cf105792b90f7425 Mon Sep 17 00:00:00 2001 From: Andrew Senetar Date: Sat, 14 Aug 2021 18:19:14 -0500 Subject: [PATCH] Minor Changes - Improve startup debugging of python errors - Fix issue with multiprocessing in newer python versions --- cocoa/dg_cocoa.py | 6 +++++- cocoa/main.m | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cocoa/dg_cocoa.py b/cocoa/dg_cocoa.py index b460c02..39abd43 100644 --- a/cocoa/dg_cocoa.py +++ b/cocoa/dg_cocoa.py @@ -6,6 +6,10 @@ import codecs, io, locale +# Force multiprocessing to use fork instead of spawn (as spawn currently causes issues) +import multiprocessing +multiprocessing.set_start_method('fork') + from hscommon.trans import install_gettext_trans_under_cocoa install_gettext_trans_under_cocoa() @@ -16,4 +20,4 @@ from inter.app import PyDupeGuru # When built under virtualenv, the dependency collector misses this module, so we have to force it # to see the module. -import distutils.sysconfig \ No newline at end of file +import distutils.sysconfig diff --git a/cocoa/main.m b/cocoa/main.m index 2893e5b..7d3655f 100644 --- a/cocoa/main.m +++ b/cocoa/main.m @@ -25,14 +25,17 @@ int main(int argc, char *argv[]) Py_Initialize(); PyGILState_STATE gilState = PyGILState_Ensure(); FILE* fp = fopen([mainpy UTF8String], "r"); - PyRun_SimpleFile(fp, [mainpy UTF8String]); + int result = PyRun_SimpleFile(fp, [mainpy UTF8String]); + if (result != 0) { + return result; + } fclose(fp); PyGILState_Release(gilState); if (gilState == PyGILState_LOCKED) { PyThreadState_Swap(NULL); PyEval_ReleaseLock(); } - int result = NSApplicationMain(argc, (const char **) argv); + result = NSApplicationMain(argc, (const char **) argv); Py_Finalize(); return result; }