From 12bfe9b23d6aedc87720e7c3aebc40b9fb2d44d0 Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Mon, 24 Oct 2016 17:55:46 -0500 Subject: [PATCH] close pipes on process end, to force flush --- CHANGELOG.md | 1 + sh.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a11a83b..45bd8342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.2 - +* bugfix where pipes passed into `_out` or `_err` were not flushed on process end [#252](https://github.com/amoffat/sh/pull/252) * deprecated `with sh.args(**kwargs)` in favor of `sh2 = sh(**kwargs)` * made `sh.pushd` thread safe * added `.kill_group()` and `.signal_group()` methods for better process control [#237](https://github.com/amoffat/sh/pull/237) diff --git a/sh.py b/sh.py index ca0e1f18..c1bb90aa 100644 --- a/sh.py +++ b/sh.py @@ -48,6 +48,7 @@ from functools import partial import inspect import tempfile +import stat import glob as glob_module import ast from contextlib import contextmanager @@ -2243,6 +2244,11 @@ def finish(): if hasattr(handler, "flush"): handler.flush() + if hasattr(handler, "fileno"): + fd_stat = os.fstat(handler.fileno()) + if stat.S_ISFIFO(fd_stat.st_mode): + handler.close() + return process, finish def get_callback_chunk_consumer(handler, encoding, decode_errors):