From 6bf64fc6ac1bb14d15608bb10e950ecbf704a289 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 19 Dec 2025 09:12:14 +0000 Subject: [PATCH 1/2] Only set signal handler in runners --- dask_jobqueue/runner.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dask_jobqueue/runner.py b/dask_jobqueue/runner.py index ac353384..edcb275e 100644 --- a/dask_jobqueue/runner.py +++ b/dask_jobqueue/runner.py @@ -15,11 +15,12 @@ from distributed.worker import Worker -# 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()) +def setup_signal_handler(): + # 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()) class Role(Enum): @@ -68,6 +69,7 @@ def __init__( asynchronous: bool = False, loop: asyncio.BaseEventLoop = None, ): + setup_signal_handler() self.status = Status.created self.scheduler = scheduler self.scheduler_address = None From ce67324f36c8dfcaa7b63f5f75eccc8927732096 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Fri, 19 Dec 2025 09:15:09 +0000 Subject: [PATCH 2/2] Reduce indirection --- dask_jobqueue/runner.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/dask_jobqueue/runner.py b/dask_jobqueue/runner.py index edcb275e..d06fcb8d 100644 --- a/dask_jobqueue/runner.py +++ b/dask_jobqueue/runner.py @@ -15,14 +15,6 @@ from distributed.worker import Worker -def setup_signal_handler(): - # 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()) - - class Role(Enum): """ This Enum contains the various roles processes can be. @@ -69,7 +61,11 @@ def __init__( asynchronous: bool = False, loop: asyncio.BaseEventLoop = None, ): - setup_signal_handler() + # 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()) self.status = Status.created self.scheduler = scheduler self.scheduler_address = None