Platforms: Unix
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
...
...