From 30c7524be5e6fdd2aaee132def4b480a9f35d4a2 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Mon, 22 Jun 2020 15:35:27 -0400 Subject: [PATCH] Fix BrokenPipeError in SpiceRecordWrapper.close() If spice-record exits for whatever reason, the wrapper will get a BrokenPipeError when trying to write to the stdin pipe. We simply ignore this error, as we will later check the exit status in wait(). --- spicerecord/wrapper.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spicerecord/wrapper.py b/spicerecord/wrapper.py index cb23285..1a982b9 100644 --- a/spicerecord/wrapper.py +++ b/spicerecord/wrapper.py @@ -59,8 +59,12 @@ def __exit__(self, *exc_info): def stop(self): if self.stopped: raise Exception("stop() already called") - self.p.stdin.write(b'Q\n') - self.p.stdin.close() + try: + self.p.stdin.write(b'Q\n') + self.p.stdin.close() + except (BrokenPipeError, IOError): + # The process has already exited + pass self.stopped = True def wait(self):