Add Alarm/Timeout Support #342

Closed
derks opened this Issue Feb 19, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@derks
Member

derks commented Feb 19, 2016

Useful to handle script timeouts using signal.alarm but might be a wider usecase to simply support timing out any operation within the app. Something like:

with CementApp('myapp') as app:
    # fail after 5 minutes (300 seconds)
    app.timer.set(300)
    app.run()
    app.timer.stop()

Wrapping the functionality of:

import signal

def timeout_handler(signum, frame):
    Raise Exception('Operation Timed Out')

with CementApp('myapp') as app:
    # fail after 5 minutes (300 seconds)
    signal.signal(signal.SIGALRM, timeout_handler)
    signal.alarm(300)

    app.run()

    signal.alarm(0)

Note that handling the signal is already possible with the builtin CementApp signal handling mechanisms. Also note that signal.alarm is only available on Unix/Linux.

@derks derks added this to the 2.8.0 Stable milestone Feb 19, 2016

@derks derks self-assigned this Feb 19, 2016

derks added a commit that referenced this issue Feb 22, 2016

@derks derks closed this Feb 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment