From c897c299fefb9c9b722b34c72e3931aa0a368f7f Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Tue, 24 Jan 2023 06:34:05 +0200 Subject: [PATCH] Unify main: - same multiprocessing start method for start.sh and setuptools entry point, - make it possible to run outside of the main thread. --- minode/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/minode/main.py b/minode/main.py index 7b52796..e3d7a18 100644 --- a/minode/main.py +++ b/minode/main.py @@ -219,9 +219,10 @@ def start_i2p_listener(): def main(): """Script entry point""" - signal.signal(signal.SIGINT, handler) - signal.signal(signal.SIGTERM, handler) - + try: + multiprocessing.set_start_method('spawn') + except RuntimeError: + pass parse_arguments() logging.basicConfig( @@ -229,6 +230,12 @@ def main(): format='[%(asctime)s] [%(levelname)s] %(message)s') logging.info('Starting MiNode') + try: + signal.signal(signal.SIGINT, handler) + signal.signal(signal.SIGTERM, handler) + except ValueError: + logging.warning('Working outside of the main thread!') + logging.info('Data directory: %s', shared.data_directory) if not os.path.exists(shared.data_directory): try: @@ -257,5 +264,4 @@ def main(): if __name__ == '__main__': - multiprocessing.set_start_method('spawn') main()