guv.timeout - universal timeouts

exception guv.timeout.Timeout(seconds=None, exception=None)[source]

Bases: BaseException

Raise exception in the current greenthread after timeout seconds.

When exception is omitted or None, the Timeout instance itself is raised. If seconds is None, 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.

pending

@property

True if the timeout is scheduled to be raised

__init__(seconds=None, exception=None)[source]
Parameters:
  • seconds (float) – timeout seconds
  • exception – exception to raise when timeout occurs
cancel() → None[source]

If the timeout is pending, cancel it

If not using Timeouts in with statements, always call cancel() in a finally after the block of code that is getting timed out. If not canceled, the timeout will be raised later on, in some unexpected section of the application.

start() → None[source]

Schedule the timeout. This is called on construction, so it should not be called explicitly, unless the timer has been canceled.

guv.timeout.with_timeout(seconds, function, *args, **kwds)[source]

Wrap a call to some (yielding) function with a timeout

If the called function fails to return before the timeout, cancel it and return a flag value.