pwnlib.timeout — Timeout handling

Timeout encapsulation, complete with countdowns and scope managers.

class pwnlib.timeout.Timeout(timeout=pwnlib.timeout.Timeout.default)[source]

Implements a basic class which has a timeout, and support for scoped timeout countdowns.

Valid timeout values are:

  • Timeout.default use the global default value (context.default)
  • Timeout.forever or None never time out
  • Any positive float, indicates timeouts in seconds

Example

>>> context.timeout = 30
>>> t = Timeout()
>>> t.timeout == 30
True
>>> t = Timeout(5)
>>> t.timeout == 5
True
>>> i = 0
>>> with t.countdown():
...     print (4 <= t.timeout and t.timeout <= 5)
...
True
>>> with t.countdown(0.5):
...     while t.timeout:
...         print round(t.timeout,1)
...         time.sleep(0.1)
0.5
0.4
0.3
0.2
0.1
>>> print t.timeout
5.0
>>> with t.local(0.5):
...     for i in range(5):
...         print round(t.timeout,1)
...         time.sleep(0.1)
0.5
0.5
0.5
0.5
0.5
>>> print t.timeout
5.0
countdown(timeout=pwnlib.timeout.Timeout.default)[source]

Scoped timeout setter. Sets the timeout within the scope, and restores it when leaving the scope.

When accessing timeout within the scope, it will be calculated against the time when the scope was entered, in a countdown fashion.

If None is specified for timeout, then the current timeout is used is made. This allows None to be specified as a default argument with less complexity.

local(timeout)[source]

Scoped timeout setter. Sets the timeout within the scope, and restores it when leaving the scope.

timeout_change()[source]

Callback for subclasses to hook a timeout change.

default = pwnlib.timeout.Timeout.default[source]

Value indicating that the timeout should not be changed

forever = None[source]

Value indicating that a timeout should not ever occur

maximum = pwnlib.timeout.maximum[source]

Maximum value for a timeout. Used to get around platform issues with very large timeouts.

OSX does not permit setting socket timeouts to 2**22. Assume that if we receive a timeout of 2**21 or greater, that the value is effectively infinite.

timeout[source]

Timeout for obj operations. By default, uses context.timeout.