From 205364f1bd4c1bf16a5b0eb0766edc1bc579adf8 Mon Sep 17 00:00:00 2001 From: Didier 'OdyX' Raboud Date: Mon, 19 Dec 2022 13:38:18 +0100 Subject: [PATCH] exiftool.terminate(); kill process unconditionally Also don't get outs nor errs from Popen.communicate() Fixes https://github.com/sylikc/pyexiftool/issues/63 --- exiftool/exiftool.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/exiftool/exiftool.py b/exiftool/exiftool.py index 54e1f7f..a87a758 100644 --- a/exiftool/exiftool.py +++ b/exiftool/exiftool.py @@ -831,7 +831,7 @@ def terminate(self, timeout: int = 30, _del: bool = False) -> None: #print("before comm", self._process.poll(), self._process) self._process.poll() # TODO freezes here on windows if subprocess zombie remains - outs, errs = self._process.communicate() # have to cleanup the process or else .poll() will return None + self._process.communicate() # have to cleanup the process or else .poll() will return None #print("after comm") # TODO a bug filed with Python, or user error... this doesn't seem to work at all ... .communicate() still hangs # https://bugs.python.org/issue43784 ... Windows-specific issue affecting Python 3.8-3.10 (as of this time) @@ -844,11 +844,10 @@ def terminate(self, timeout: int = 30, _del: bool = False) -> None: On Linux, this runs as is, and the process terminates properly """ self._process.communicate(input=b"-stay_open\nFalse\n", timeout=timeout) # this is a constant sequence specified by PH's exiftool - self._process.kill() except subprocess.TimeoutExpired: # this is new in Python 3.3 (for python 2.x, use the PyPI subprocess32 module) - self._process.kill() - outs, errs = self._process.communicate() - # err handling code from https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate + pass + # In any case, kill the process. + self._process.kill() self._flag_running_false()