Created
November 8, 2017 10:23
-
-
Save bofm/721c4d824f71233a37b64da50dfe96c0 to your computer and use it in GitHub Desktop.
set maximum execution time for a python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
def set_run_timeout(timeout): | |
"""Set maximum execution time of the current Python process""" | |
def alarm(*_): | |
raise SystemExit("Timed out!") | |
signal.signal(signal.SIGALRM, alarm) | |
signal.alarm(timeout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment