Skip to content

Expose details in worker timeout exceptions #9092

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
7 changes: 3 additions & 4 deletions distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
WorkerPlugin,
_get_plugin_name,
)
from distributed.exceptions import WorkerStartTimeoutError
from distributed.metrics import time
from distributed.objects import HasWhat, SchedulerInfo, WhoHas
from distributed.protocol import to_serialize
Expand Down Expand Up @@ -1651,10 +1652,8 @@ def running_workers(info):

while running_workers(info) < n_workers:
if deadline and time() > deadline:
raise TimeoutError(
"Only %d/%d workers arrived after %s"
% (running_workers(info), n_workers, timeout)
)
assert timeout is not None
raise WorkerStartTimeoutError(running_workers(info), n_workers, timeout)
await asyncio.sleep(0.1)
info = await self.scheduler.identity()
self._scheduler_identity = SchedulerInfo(info)
Expand Down
6 changes: 3 additions & 3 deletions distributed/deploy/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from distributed.compatibility import PeriodicCallback
from distributed.core import Status
from distributed.deploy.adaptive import Adaptive
from distributed.exceptions import WorkerStartTimeoutError
from distributed.metrics import time
from distributed.objects import SchedulerInfo
from distributed.utils import (
Expand Down Expand Up @@ -610,9 +611,8 @@ def running_workers(info):

while n_workers and running_workers(self.scheduler_info) < n_workers:
if deadline and time() > deadline:
raise TimeoutError(
"Only %d/%d workers arrived after %s"
% (running_workers(self.scheduler_info), n_workers, timeout)
raise WorkerStartTimeoutError(
running_workers(self.scheduler_info), n_workers, timeout
)
await asyncio.sleep(0.1)

Expand Down
33 changes: 33 additions & 0 deletions distributed/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from asyncio import TimeoutError


class Reschedule(Exception):
"""Reschedule this task
Expand All @@ -13,3 +15,34 @@ class Reschedule(Exception):
load across the cluster has significantly changed since first scheduling
the task.
"""


class WorkerStartTimeoutError(TimeoutError):
"""Raised when the expected number of workers to not start within the timeout period."""

def __init__(
self, available_workers: int, expected_workers: int, timeout: float
) -> None:
super().__init__(available_workers, expected_workers, timeout)

@property
def available_workers(self) -> int:
"""Number of workers that are available."""
return self.args[0]
Comment on lines +28 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not seen exceptions implemented this way before with properties pointing to arg indices. There's a code smell here I can't quite put my finger on, it feels brittle.

Why not set the attributes explicitly during the __init__?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah, I totally agree! I had originally set the attributes in __init__ but noticed that other custom exceptions in this project were following this (odd) pattern so just went with it for consistency. Happy to revert back to my original approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One example of the existing pattern:

class KilledWorker(Exception):


@property
def expected_workers(self) -> int:
"""Number of workers that were expected to be available."""
return self.args[1]

@property
def timeout(self) -> float:
"""Timeout period in seconds."""
return self.args[2]

def __str__(self) -> str:
return "Only %d/%d workers arrived after %s" % (
self.available_workers,
self.expected_workers,
self.timeout,
)
Loading