Alarm
Last updated
Last updated
import time
from cement import App, CaughtSignal
class MyApp(App):
class Meta:
label = 'myapp'
exit_on_close = True
extensions = ['alarm']
with MyApp() as app:
try:
app.run()
app.alarm.set(3, "The operation timed out after 3 seconds!")
# do something that takes time to operate
time.sleep(5)
app.alarm.stop()
except CaughtSignal as e:
print(e.msg)
app.exit_code = 1$ python myapp.py
ERROR: The operation timed out after 3 seconds!
Caught signal 14