Skip to content

Instantly share code, notes, and snippets.

@cedricporter
Created July 10, 2014 11:42
Show Gist options
  • Save cedricporter/3b5881f613a6c84041c3 to your computer and use it in GitHub Desktop.
Save cedricporter/3b5881f613a6c84041c3 to your computer and use it in GitHub Desktop.

Revisions

  1. cedricporter created this gist Jul 10, 2014.
    24 changes: 24 additions & 0 deletions signal_handler_me_understand.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # 1,2,3,4,5,-1,0,1,2...
    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:
    x = count
    count += 1
    print count

    if __name__ == "__main__":
    main()