Package grassyknoll :: Package concurrent :: Module lib :: Class TimeOut
[hide private]

Class TimeOut

source code


TimeOut helps manage timeouts that are spread across several operations.

Create it with the maximum amount of time you want to wait:
>>> import time
>>> timeout=TimeOut(0.5)

Calling the object will return the amount of time left: >>> time.sleep(.3) >>> timeout() # doctest:+SKIP 0.2

If you run out of time, calling a TimeOut will return zero: >>> time.sleep(.3) >>> timeout() 0.0

If you pass None as max_time, you get None back: >>> timeout=TimeOut(None) >>> timeout() is None True

Instance Methods [hide private]
 
__init__(self, max_time)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__call__(self) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Instance Variables [hide private]
float or None end_time
when time is up
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, max_time)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Parameters:
  • max_time (float or None) - maximum time to wait, in seconds, or None, to wait forever
Overrides: object.__init__