Timeout¶
- class controller.timeout.Timeout(operation, timeout, user=None)¶
Bases:
object
Track a cumulative timeout on a series of operations.
Many Nublado controller operations involve operations that support individual timeouts, where all operations must complete within a total timeout. Examples include spawning a lab or creating a user file server. This class encapsulates that type of timeout and provides methods to retrieve timeouts for individual operations.
- Parameters:
Methods Summary
elapsed
()Elapsed time since the timeout started.
enforce
()Enforce the timeout and translate
TimeoutError
.left
()Return the amount of time remaining in seconds.
partial
(timeout)Create a timeout that is an extension of this timeout.
Methods Documentation
- elapsed()¶
Elapsed time since the timeout started.
- Returns:
Seconds elapsed since the object was created.
- Return type:
- enforce()¶
Enforce the timeout and translate
TimeoutError
.Used to wrap a block of code in
asyncio.timeout
and catch anyTimeoutError
, translating it intoControllerTimeoutError
with additional context.- Raises:
ControllerTimeoutError – Raised if
TimeoutError
was raised inside the enclosed operation.- Return type:
- left()¶
Return the amount of time remaining in seconds.
- Returns:
Time remaining in the timeout in seconds.
- Return type:
- Raises:
ControllerTimeoutError – Raised if the timeout has expired.
- partial(timeout)¶
Create a timeout that is an extension of this timeout.
In some cases, such as after a watch for object deletion times out, we want to perform several operations that fit within an overall timeout. This method returns a timeout that is shorter than an overall timeout, with the same metadata, which can be used for a sub-operation.
- Parameters:
timeout (
timedelta
) – Maximum duration of timeout. The newly-created timeout will be capped at the remaining duration of the parent timeout.- Returns:
Child timeout.
- Return type:
- Raises:
ControllerTimeoutError – Raised if the timeout parameter is less than 0, which may happen if it is constructed by subtracting some time from the remaining time in the timeout.