Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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