Skip to content

Instantly share code, notes, and snippets.

@cedricporter
Created July 10, 2014 11:41
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 cedricporter/c439e175b74b8e85b661 to your computer and use it in GitHub Desktop.
Save cedricporter/c439e175b74b8e85b661 to your computer and use it in GitHub Desktop.
signal handler surprises me
# print 1,2,3,4,5,-1,6,7,8...
import signal
import sys
count = 0
def signal_handler(signum, frame):
global count
count = -1
print 'sig', count
def main():
signal.signal(signal.SIGALRM, signal_handler)
signal.setitimer(signal.ITIMER_REAL, 1, 1)
global count
while True:
for line in sys.stdin:
count += 1
print count
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment