Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

kgodlewski
Copy link
Contributor

@kgodlewski kgodlewski commented Oct 4, 2024

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 optional timeout argument as well.

Important

Note that this PR changes the semantics of timeout making it raise TimeoutError instead of simply returning from a wait*() method. Previously the timeout argument wouldn't really do anything useful.

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.
Copy link
Contributor

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
Copy link
Contributor

@michalsosn michalsosn Oct 7, 2024

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.
@kgodlewski kgodlewski force-pushed the kg/default-timeout-for-wait-operations branch from 58ca5a0 to d6397b5 Compare October 16, 2024 12:12
@kgodlewski kgodlewski marked this pull request as draft November 6, 2024 09:58
@kgodlewski kgodlewski closed this Jan 10, 2025
@kgodlewski kgodlewski deleted the kg/default-timeout-for-wait-operations branch April 7, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants