Managing timeouts

Timeout objects allow to stop a task after a given amount of time. This is useful to abort a network connection if the response is taking too long to arrive, for example.

class evergreen.timeout.Timeout([seconds[, exception]])

Raises exception in the current task after timeout seconds.

When exception is omitted or None, the Timeout instance itself is raised. If seconds is None or < 0, the timer is not scheduled, and is only useful if you’re planning to raise it directly.

Timeout objects are context managers, and so can be used in with statements. When used in a with statement, if exception is False, the timeout is still raised, but the context manager suppresses it, so the code outside the with-block won’t see it.

start()

Start the Timeout object.

cancel()

Prevent the Timeout from raising, if hasn’t done so yet.

Previous topic

Task local storage

Next topic

Futures

This Page