From f2cac09f6f1d0b5601a045c672fdae6701fa783c Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 23 Oct 2018 23:45:12 +0200 Subject: [PATCH] Fix a problem when dealing with huge files: file cmd responds before all the content has been writed --- archive.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archive.py b/archive.py index a0beb29..ebba1fa 100644 --- a/archive.py +++ b/archive.py @@ -62,8 +62,11 @@ def _guess_mime(data): "--brief", "--mime-type", "-"], env={"LANG": 'C'}, stdin=subprocess.PIPE, stdout=subprocess.PIPE) as p: - p.stdin.write(data.encode() if isinstance(data, str) else data) - p.stdin.close() + try: + p.stdin.write(data.encode() if isinstance(data, str) else data) + p.stdin.close() + except BrokenPipeError: + pass p.wait() if p.returncode == 0: return p.stdout.read().decode('utf-8', 'replace').strip()