Skip to content

Instantly share code, notes, and snippets.

@duydo
Forked from felipecruz/timeout.py
Last active August 29, 2015 14:06
Show Gist options
  • Save duydo/73e287b21522fed16522 to your computer and use it in GitHub Desktop.
Save duydo/73e287b21522fed16522 to your computer and use it in GitHub Desktop.
import signal
def signal_handler(signum, frame):
raise Exception("Timed out!")
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(10) # Ten seconds
try:
long_function_call()
except Exception:
print "Timed out!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment