Skip to content

Instantly share code, notes, and snippets.

@shanemhansen
Created September 14, 2012 19:10
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 shanemhansen/3724043 to your computer and use it in GitHub Desktop.
Save shanemhansen/3724043 to your computer and use it in GitHub Desktop.
cancel a read
import sys
import signal
class Alarm(Exception):
pass
def alarm_handler(signum, frame):
raise Alarm()
signal.signal(signal.SIGALRM, alarm_handler)
try:
signal.alarm(2)
sys.stdin.read()
except Alarm:
print "read canceled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment