From b07308ea36da20ba4a109e53799e1dc26b613762 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Thu, 5 Sep 2024 11:23:13 +0100 Subject: [PATCH] Only add signal handler on main thread (#668) * Only add signal handler on main thread * Add comment to explain reasoning --- dask_jobqueue/runner.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dask_jobqueue/runner.py b/dask_jobqueue/runner.py index 60da426e..ac353384 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,10 @@ # Close gracefully when receiving a SIGINT -signal.signal(signal.SIGINT, lambda *_: sys.exit()) +# 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()) class Role(Enum):