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:
  • operation (str) – Human-readable name of operation, for error reporting.

  • timeout (timedelta) – Duration of the timeout.

  • user (str | None, default: None) – If given, user associated with the timeout, for error reporting.

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:

float

enforce()

Enforce the timeout and translate TimeoutError.

Used to wrap a block of code in asyncio.timeout and catch any TimeoutError, translating it into ControllerTimeoutError with additional context.

Raises:

ControllerTimeoutError – Raised if TimeoutError was raised inside the enclosed operation.

Return type:

AsyncIterator[None]

left()

Return the amount of time remaining in seconds.

Returns:

Time remaining in the timeout in seconds.

Return type:

float

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:

Timeout

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.