-
-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Make workers gracefully handle sigint #2844
Open
jni
wants to merge
6
commits into
dask:main
Choose a base branch
from
jni:worker-sigint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
79de8ce
Test worker does not raise TimeoutError on sigint
jni bfd0df9
Unregister nannies on sigint to prevent errors
jni 8185c67
Add note about limitation of test structure
jni b907679
WIP: 'incorrect' timeouterror from tornado shouldn't be re-raised
jni 8770d44
Support SIGINT from dask-worker
mrocklin 62883f1
Skip windows test
mrocklin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import asyncio | ||
import atexit | ||
import functools | ||
import logging | ||
import gc | ||
import os | ||
|
@@ -13,7 +14,7 @@ | |
from dask.system import CPU_COUNT | ||
from distributed import Nanny, Worker | ||
from distributed.security import Security | ||
from distributed.cli.utils import check_python_3, install_signal_handlers | ||
from distributed.cli.utils import check_python_3 | ||
from distributed.comm import get_address_host_port | ||
from distributed.preloading import validate_preload_argv | ||
from distributed.proctitle import ( | ||
|
@@ -386,26 +387,32 @@ def del_pid_file(): | |
for i in range(nprocs) | ||
] | ||
|
||
async def close_all(): | ||
# Unregister all workers from scheduler | ||
if nanny: | ||
await asyncio.gather(*[n.close(timeout=2) for n in nannies]) | ||
|
||
signal_fired = False | ||
|
||
def on_signal(signum): | ||
async def _on_signal(signum): | ||
nonlocal signal_fired | ||
signal_fired = True | ||
if signum != signal.SIGINT: | ||
from distributed.utils import log_errors | ||
|
||
with log_errors(): | ||
logger.info("Exiting on signal %d", signum) | ||
asyncio.ensure_future(close_all()) | ||
signal_fired = True | ||
if signum == signal.SIGINT: | ||
logger.info("Gracefully closing worker because of SIGINT call") | ||
await asyncio.gather(*[n.close_gracefully() for n in nannies]) | ||
logger.info("Closing workers") | ||
await asyncio.gather(*[n.close() for n in nannies]) | ||
|
||
def on_signal(sig): | ||
asyncio.ensure_future(_on_signal(sig)) | ||
|
||
async def run(): | ||
await asyncio.gather(*nannies) | ||
await asyncio.gather(*[n.finished() for n in nannies]) | ||
|
||
install_signal_handlers(loop, cleanup=on_signal) | ||
|
||
for sig in [signal.SIGINT, signal.SIGTERM]: | ||
asyncio.get_event_loop().add_signal_handler( | ||
sig, functools.partial(on_signal, sig) | ||
) | ||
Comment on lines
+412
to
+415
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect windows will not be happy with this. https://stackoverflow.com/questions/45987985/asyncio-loops-add-signal-handler-in-windows |
||
try: | ||
loop.run_sync(run) | ||
except TimeoutError: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be reasonable to give SIGTERM the same treatment as SIGINT as well?