Skip to content

Instantly share code, notes, and snippets.

@greenarrow
Created February 13, 2015 12:30
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 greenarrow/3fa735ba16bae6311c36 to your computer and use it in GitHub Desktop.
Save greenarrow/3fa735ba16bae6311c36 to your computer and use it in GitHub Desktop.
How to make Python play nicely with pipes
import sys
import errno
def main():
for i in range(20):
print i
if __name__ == "__main__":
# ensure buffer is flushed before we handle SIGPIPE
try:
try:
main()
finally:
sys.stdout.flush()
except IOError, e:
if e.errno != errno.EPIPE:
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment