Timeout
Pactole Index / Utils / Timeout
Auto-generated documentation for utils.timeout module.
Timeout
A class to represent a timeout duration.
Arguments
secondsfloat - The duration of the timeout in seconds.startbool, optional - Whether to start the timeout immediately. Defaults to True.
Examples
>>> timeout = Timeout(5)
>>> timeout.seconds
5
>>> timeout.elapsed
0.0
>>> timeout.remaining
5.0
>>> timeout.expired
False
>>> time.sleep(6)
>>> timeout.elapsed
6.0
>>> timeout.remaining
0.0
>>> timeout.expired
True
>>> timeout.reset()
>>> timeout.elapsed
0.0
>>> timeout.remaining
5.0
>>> timeout.expired
False
Signature
Timeout().elapsed
Return the elapsed time since the timeout was started.
Returns
float- The elapsed time in seconds.
Examples
Signature
Timeout().expired
Return True if the timeout has expired, False otherwise.
Returns
bool- True if the timeout has expired, False otherwise.
Examples
Signature
Timeout().remaining
Return the remaining time before the timeout expires.
Returns
float- The remaining time in seconds.
Examples
Signature
Timeout().reset
Reset the timeout to start counting from now.
Examples
>>> timeout = Timeout(5)
>>> time.sleep(3)
>>> timeout.elapsed
3.0
>>> timeout.reset()
>>> timeout.elapsed
0.0
Signature
Timeout().seconds
Return the timeout duration in seconds.
Returns
float- The timeout duration in seconds.
Examples
Signature
Timeout().seconds
Set the timeout duration in seconds.
Arguments
valuefloat - The new timeout duration in seconds.
Examples
Signature
Timeout().start
Start the timeout.
Examples
>>> timeout = Timeout(5, start=False)
>>> timeout.expired
False
>>> timeout.start()
>>> timeout.expired
False
>>> time.sleep(6)
>>> timeout.expired
True
Signature
Timeout().started
Return whether the timeout has been started.
Returns
bool- True if the timeout has been started, False otherwise.
Examples
>>> timeout = Timeout(5, start=False)
>>> timeout.started
False
>>> timeout.start()
>>> timeout.started
True
Signature
Timeout().stop
Stop the timeout.
Examples
>>> timeout = Timeout(5)
>>> time.sleep(2)
>>> timeout.stop()
>>> timeout.elapsed
2.0
>>> timeout.remaining
3.0
>>> timeout.expired
False