-
-
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
Don't heartbeat while Worker is closing #6543
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
|
||
from distributed import Scheduler, system | ||
from distributed import versions as version_module | ||
from distributed.batched import BatchedSend | ||
from distributed.client import Client, _global_clients, default_client | ||
from distributed.comm import Comm | ||
from distributed.comm.tcp import TCP | ||
|
@@ -2345,3 +2346,33 @@ def freeze_data_fetching(w: Worker, *, jump_start: bool = False): | |
if jump_start: | ||
w.status = Status.paused | ||
w.status = Status.running | ||
|
||
|
||
@contextmanager | ||
def freeze_batched_send(bcomm: BatchedSend) -> Iterator[LockedComm]: | ||
""" | ||
Contextmanager blocking writes to a `BatchedSend` from sending over the network. | ||
|
||
The returned `LockedComm` object can be used for control flow and inspection via its | ||
``read_event``, ``read_queue``, ``write_event``, and ``write_queue`` attributes. | ||
|
||
On exit, any writes that were blocked are un-blocked, and the original comm of the | ||
`BatchedSend` is restored. | ||
""" | ||
assert not bcomm.closed() | ||
assert bcomm.comm | ||
assert not bcomm.comm.closed() | ||
orig_comm = bcomm.comm | ||
|
||
write_event = asyncio.Event() | ||
write_queue: asyncio.Queue = asyncio.Queue() | ||
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. nit: is it actually necessary to explicitly annotate this? That feels absurd. 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. Yes, mypy actually raised an error explicitly telling me to do this. I agree it's absurd. |
||
|
||
bcomm.comm = locked_comm = LockedComm( | ||
orig_comm, None, None, write_event, write_queue | ||
) | ||
|
||
try: | ||
yield locked_comm | ||
finally: | ||
write_event.set() | ||
bcomm.comm = orig_comm |
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.
FWIW I'm inclined to change this eventually and reuse the stream for heartbeats