The Alarm Extension provides the AlarmManager extended object, with easy mechanisms for handling long running operations that might timeout after a set amount of time.
- No external dependencies
As of Cement 3.0.8, applications using optional extensions should include them in their dependencies for future compatibility in the event additional dependencies are required:
- macOS (Darwin)
This extension does not rely on any application level configuration settings or meta options.
Example: Using Alarm Extension
from cement import App, CaughtSignal
label = 'myapp'
exit_on_close = True
extensions = ['alarm']
with MyApp() as app:
app.alarm.set(3, "The operation timed out after 3 seconds!")
# do something that takes time to operate
except CaughtSignal as e:
app.exit_code = 1
$ python myapp.py
ERROR: The operation timed out after 3 seconds!
Caught signal 14