-
-
Notifications
You must be signed in to change notification settings - Fork 733
Clean up cluster
process reaping
#6840
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
Merged
gjoseph92
merged 1 commit into
dask:main
from
gjoseph92:improve-cluster-contextmanager-kill
Aug 18, 2022
Merged
Changes from all commits
Commits
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 hidden or 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 |
---|---|---|
|
@@ -568,14 +568,14 @@ def security(): | |
return tls_only_security() | ||
|
||
|
||
def _kill_join(proc, timeout): | ||
proc.kill() | ||
proc.join(timeout) | ||
if proc.is_alive(): | ||
raise multiprocessing.TimeoutError( | ||
f"Process {proc} did not shut down within {timeout}s" | ||
) | ||
proc.close() | ||
def _kill_join_processes(processes): | ||
# Join may hang or cause issues, so make sure all are killed first. | ||
# Note that we don't use a timeout, but rely on the overall pytest timeout. | ||
for proc in processes: | ||
proc.kill() | ||
for proc in processes: | ||
proc.join() | ||
proc.close() | ||
|
||
|
||
def _close_queue(q): | ||
|
@@ -590,15 +590,13 @@ def cluster( | |
nanny=False, | ||
worker_kwargs=None, | ||
active_rpc_timeout=10, | ||
shutdown_timeout=20, | ||
scheduler_kwargs=None, | ||
config=None, | ||
): | ||
worker_kwargs = worker_kwargs or {} | ||
scheduler_kwargs = scheduler_kwargs or {} | ||
config = config or {} | ||
|
||
ws = weakref.WeakSet() | ||
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. Unused in function (and |
||
enable_proctitle_on_children() | ||
|
||
with check_process_leak(check=True), check_instances(), config_for_cluster_tests(): | ||
|
@@ -608,6 +606,8 @@ def cluster( | |
_run_worker = run_worker | ||
|
||
with contextlib.ExitStack() as stack: | ||
processes = [] | ||
stack.callback(_kill_join_processes, processes) | ||
# The scheduler queue will receive the scheduler's address | ||
scheduler_q = get_mp_context().Queue() | ||
stack.callback(_close_queue, scheduler_q) | ||
|
@@ -620,9 +620,8 @@ def cluster( | |
kwargs=scheduler_kwargs, | ||
daemon=True, | ||
) | ||
ws.add(scheduler) | ||
scheduler.start() | ||
stack.callback(_kill_join, scheduler, shutdown_timeout) | ||
processes.append(scheduler) | ||
|
||
# Launch workers | ||
workers_by_pid = {} | ||
|
@@ -642,9 +641,8 @@ def cluster( | |
args=(q, scheduler_q, config), | ||
kwargs=kwargs, | ||
) | ||
ws.add(proc) | ||
proc.start() | ||
stack.callback(_kill_join, proc, shutdown_timeout) | ||
processes.append(proc) | ||
workers_by_pid[proc.pid] = {"proc": proc} | ||
|
||
saddr_or_exception = scheduler_q.get() | ||
|
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.
Unused in codebase