concurrence.timer – A timer module

Platforms: Unix

class concurrence.timer.Timeout

Task based timeout. The Timeout class lets you set a timeout for the current task. If the task takes longer than timeout seconds after the timeout is set, a TimeoutError is raised inside the task.

Timeouts form a stack and you can always push() a new timeout on top of the current one. Every push() must be matched by a corresponding call to pop(). As a convenience you can use pythons with statement to do the pop automatically.

Timeout example:

with Timeout.push(30):  #everything in following block must be finished within 30 seconds
    ...
    ...
    with Timeout.push(5):
        cnn = get_database_connection() #must return within 5 seconds
    ...
    ...
classmethod current()
Gets the current timeout for the current task in seconds. That is the number of seconds before the current task will timeout by raising a TimeoutError. A timeout of -1 indicates that there is no timeout for the current task.
classmethod pop()
Pops the current timeout for the current task.
classmethod push(timeout)
Pushes a new timeout in seconds for the current task.

Previous topic

concurrence.io – The concurrence io module

Next topic

concurrence.http – The concurrence http module

This Page