Skip to content

Instantly share code, notes, and snippets.

@fulmicoton
Created August 21, 2014 15:16
Show Gist options
  • Save fulmicoton/b2422827f917502eb484 to your computer and use it in GitHub Desktop.
Save fulmicoton/b2422827f917502eb484 to your computer and use it in GitHub Desktop.
import csv
from contextlib import contextmanager
import sys
@contextmanager
def getstdin():
try:
yield sys.stdin # process.stdout
print "a"
except Exception as e:
print "b", e
except GeneratorExit as e:
# generator exit is considered regular.
# it happens for with the timeout exception.
print "c"
finally:
print "d"
print "START"
with getstdin() as in_stream:
for row in csv.reader(in_stream, delimiter=","):
print row
print "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment