Skip to content

Instantly share code, notes, and snippets.

@whymarrh
Created January 6, 2021 17:32
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 whymarrh/119730855d372409dabcd4b1a06a91c9 to your computer and use it in GitHub Desktop.
Save whymarrh/119730855d372409dabcd4b1a06a91c9 to your computer and use it in GitHub Desktop.
Exit graceful on SIGPIPE
#!/usr/bin/env python -u
from __future__ import print_function
import signal
import sys
import time
def exit_graceful(sig, frame):
print('GRACEFUL', file=open("was-graceful.log", "wt"))
sys.exit(0)
signal.signal(signal.SIGPIPE, exit_graceful)
try:
i = 0
while True:
i += 1
print(i)
time.sleep(1)
except Exception as e:
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment