From f8890706f92eb86dcb46f56d04c50d9f5ebb95a9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 10 Mar 2014 20:30:03 -0400 Subject: [PATCH] - Suppressed IOErrors which can raise when program output pipe is closed under a program like ``head``; however this only works on Python 2. On Python 3, there is not yet a known way to suppress the BrokenPipeError warnings without prematurely terminating the program via signals. fixes #160. Added comments to http://bugs.python.org/issue11380 to see what the status is on py3k. --- alembic/util.py | 8 +++++++- docs/build/changelog.rst | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/alembic/util.py b/alembic/util.py index 26f7ac09..9f035dec 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -140,7 +140,13 @@ def write_outstream(stream, *text): if not isinstance(t, binary_type): t = t.encode(encoding, 'replace') t = t.decode(encoding) - stream.write(t) + try: + stream.write(t) + except IOError: + # suppress "broken pipe" errors. + # no known way to handle this on Python 3 however + # as the exception is "ignored" (noisily) in TextIOWrapper. + break def coerce_resource_to_filename(fname): """Interpret a filename as either a filesystem location or as a package resource. diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index 2c592ab3..f32bb9b3 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -5,6 +5,16 @@ Changelog .. changelog:: :version: 0.6.4 + .. change:: + :tags: bug + :tickets: 160 + + Suppressed IOErrors which can raise when program output pipe + is closed under a program like ``head``; however this only + works on Python 2. On Python 3, there is not yet a known way to + suppress the BrokenPipeError warnings without prematurely terminating + the program via signals. + .. change:: :tags: bug :tickets: 179 -- 2.47.2