-
Notifications
You must be signed in to change notification settings - Fork 87
Add custom timeout exception to be raised upon timeout in status.wait(timeout=2...) #1263
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -439,7 +439,7 @@ def exception(self, timeout=None): | |
| return self._exception | ||
|
|
||
| @tracer.start_as_current_span(f"{_TRACE_PREFIX} wait") | ||
| def wait(self, timeout=None): | ||
| def wait(self, timeout=None, timeout_exception=None): | ||
| """ | ||
| Block until the action completes. | ||
|
|
||
|
|
@@ -451,6 +451,11 @@ def wait(self, timeout=None): | |
| timeout: Union[Number, None], optional | ||
| If None (default) wait indefinitely until the status finishes. | ||
|
|
||
| timeout_exception: Exception, optional | ||
| If None (default), WaitTimeoutError will be raised if the status | ||
| does not complete within ``timeout``. If this is set to an Exception, | ||
| that exception will be raised instead. | ||
|
|
||
| Raises | ||
| ------ | ||
| WaitTimeoutError | ||
|
|
@@ -465,9 +470,14 @@ def wait(self, timeout=None): | |
| indicates that the action itself raised ``TimeoutError``, distinct | ||
| from ``WaitTimeoutError`` above. | ||
| """ | ||
| exception_to_raise = ( | ||
|
Contributor
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. Creating the exception grabs things about the current stack, we should not create it until we need it. |
||
| timeout_exception | ||
| if isinstance(timeout_exception, Exception) | ||
|
Member
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. One thing to consider: we might want to fail loudly with a TypeError if the user passes a non-exception non-None here. |
||
| else WaitTimeoutError(f"Status {self!r} has not completed yet.") | ||
| ) | ||
| _set_trace_attributes(trace.get_current_span(), self._trace_attributes) | ||
| if not self._event.wait(timeout=timeout): | ||
| raise WaitTimeoutError(f"Status {self!r} has not completed yet.") | ||
| raise exception_to_raise | ||
| if self._exception is not None: | ||
| raise self._exception | ||
|
|
||
|
|
||
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.
This should be the class to raise not an instantiated exception.