-
Notifications
You must be signed in to change notification settings - Fork 1
Add a global default timeout for all wait() operations. #49
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
Conversation
src/neptune_scale/__init__.py
Outdated
timeout (float, optional): Maximum time in seconds to wait for the remaining operations to complete. | ||
If the timeout is reached, `TimeoutError` is raised. | ||
If the argument is not provided, the value of the `NEPTUNE_OPERATIONS_TIMEOUT_SECONDS` | ||
environment variable is used. If the variable is not set, the default value of 1800 seconds is used. |
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.
there's no way to retry forever/disable timeout?
@@ -611,6 +627,11 @@ def _wait( | |||
wait_condition.wait(timeout=wait_time) | |||
value = wait_value.value | |||
|
|||
timeout_left -= time.monotonic() - t0 |
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.
why are you doing it this way instead of the usual (at least I've seen this pattern in this codebase)
start_time = time.monotonic()
while True:
..
time_elapsed = time.monotonic() - start_time
if time_elapsed > timeout:
boom
?
Your implementation may wait longer than the specified timeout, because you are moving the t0 on each loop and thus ignoring the time of executing BLOCK B
while True:
t0 = time.monotonic() ## stores e.g. 1000ms, 2000ms, 3000ms on each iteration
BLOCK A # ~900ms passes
timeout_left = time.monotonic() - t0 ## subtracts e.g. 1900ms - 1000ms, 2900 - 2000, 3900 - 3000...
BLOCK B # ~100ms passes, but it's not subtracted from timeout_left
The timeout is configurable via `NEPTUNE_OPERATIONS_TIMEOUT_SECONDS` env variable. `Run.close()` now accepts an optional `timeout` argument as well.
58ca5a0
to
d6397b5
Compare
The timeout is configurable via
NEPTUNE_OPERATIONS_TIMEOUT_SECONDS
env variable. If not provided via the env or method arguments, the default timeout is 300 sec.Run.close()
now accepts an optionaltimeout
argument as well.Important
Note that this PR changes the semantics of
timeout
making it raiseTimeoutError
instead of simply returning from await*()
method. Previously thetimeout
argument wouldn't really do anything useful.