Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,11 @@ async def done_callback(future, callback):
"""
while future.status == "pending":
await future._state.wait()
callback(future)
try:
callback(future)
except RuntimeError as e:
if "shutdown" not in str(e) and "interpreter" not in str(e):
raise


class AllExit(Exception):
Expand Down
21 changes: 21 additions & 0 deletions distributed/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8435,3 +8435,24 @@ def reducer(futs, *, offset=0, **kwargs):

result = await future.result()
assert result == 30 if not offset else 31


@gen_cluster(client=True)
async def test_done_callback_shutdown_runtime_error(c, s, a, b):
from distributed.client import done_callback

future = c.submit(inc, 1)
await future

# Shutdown-related RuntimeError is swallowed
def cb_shutdown(fut):
raise RuntimeError("cannot schedule new futures after interpreter shutdown")

await done_callback(future, cb_shutdown)

# Unrelated RuntimeError is re-raised
def cb_other(fut):
raise RuntimeError("something else")

with pytest.raises(RuntimeError, match="something else"):
await done_callback(future, cb_other)
Loading