From 1bbbfb2a13ecfdff6d43c9ab1b33fe94bef5571e Mon Sep 17 00:00:00 2001 From: James Douglass Date: Wed, 11 Sep 2024 14:42:19 -0700 Subject: [PATCH] Moving multiprocessing.freeze_support() to __main__.py. RE:#1622 --- exe/hooks/rthook.py | 5 +---- src/natcap/invest/__main__.py | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/exe/hooks/rthook.py b/exe/hooks/rthook.py index 53a9af14b6..ec0b3264a8 100644 --- a/exe/hooks/rthook.py +++ b/exe/hooks/rthook.py @@ -1,9 +1,6 @@ -import sys import os -import multiprocessing import platform - -multiprocessing.freeze_support() +import sys os.environ['PROJ_LIB'] = os.path.join(sys._MEIPASS, 'proj') diff --git a/src/natcap/invest/__main__.py b/src/natcap/invest/__main__.py index 1f68c51913..167e0fc170 100644 --- a/src/natcap/invest/__main__.py +++ b/src/natcap/invest/__main__.py @@ -1,5 +1,11 @@ +import multiprocessing import sys +# We want to guarantee that this is called BEFORE any other processes start, +# which could happen at import time. +if __name__ == '__main__': + multiprocessing.freeze_support() + from . import cli if __name__ == '__main__':