Skip to content

Instantly share code, notes, and snippets.

@bofm
Created November 8, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bofm/721c4d824f71233a37b64da50dfe96c0 to your computer and use it in GitHub Desktop.
Save bofm/721c4d824f71233a37b64da50dfe96c0 to your computer and use it in GitHub Desktop.
set maximum execution time for a python script
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