From 6a90b42cd830473a8aa8a3811d324ff98613beeb Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Thu, 29 Aug 2024 07:24:19 +0100 Subject: [PATCH 1/2] Only add signal handler on main thread --- dask_jobqueue/runner.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dask_jobqueue/runner.py b/dask_jobqueue/runner.py index 60da426e..cf6564b7 100644 --- a/dask_jobqueue/runner.py +++ b/dask_jobqueue/runner.py @@ -4,6 +4,7 @@ import signal from contextlib import suppress from enum import Enum +import threading from typing import Dict, Optional import warnings from tornado.ioloop import IOLoop @@ -15,7 +16,8 @@ # Close gracefully when receiving a SIGINT -signal.signal(signal.SIGINT, lambda *_: sys.exit()) +if threading.current_thread() is threading.main_thread(): + signal.signal(signal.SIGINT, lambda *_: sys.exit()) class Role(Enum): From b5f319039812b3f723de71be765b3ec3b7e8c2ee Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Thu, 29 Aug 2024 07:53:10 +0100 Subject: [PATCH 2/2] Add comment to explain reasoning --- dask_jobqueue/runner.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dask_jobqueue/runner.py b/dask_jobqueue/runner.py index cf6564b7..ac353384 100644 --- a/dask_jobqueue/runner.py +++ b/dask_jobqueue/runner.py @@ -16,6 +16,8 @@ # Close gracefully when receiving a SIGINT +# We use SIGINT to shut down because the scheduler and worker hang +# if we call sys.exit() see https://github.com/dask/distributed/issues/8644 if threading.current_thread() is threading.main_thread(): signal.signal(signal.SIGINT, lambda *_: sys.exit())