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.defaultuse the global default value (context.default)Timeout.foreverorNonenever time outAny 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 ... >>> 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
timeoutwithin the scope, it will be calculated against the time when the scope was entered, in a countdown fashion.If
Noneis specified fortimeout, then the current timeout is used is made. This allowsNoneto 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.
- default = pwnlib.timeout.Timeout.default[source]
Value indicating that the timeout should not be changed