From 8206770c0af94d84a48f53024cdaa0d0e1d67335 Mon Sep 17 00:00:00 2001 From: Peter Grayson Date: Mon, 23 Aug 2021 16:35:10 -0400 Subject: [PATCH] Do not close stdin before killing child bg process Addresses #78 Closing stdin of the child git process to terminate itself. On Windows, the subsequent attempt to kill the already-terminating child process results in an exception (PermissionError or WindowsError or OSError). On Linux, the terminated child process remains in a defunct/zombie state so that the subsequent kill is idempotent and the child is finalized by wait(). Signed-off-by: Peter Grayson --- stgit/lib/git/repository.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/stgit/lib/git/repository.py b/stgit/lib/git/repository.py index 2b7a9a3..6e93b69 100644 --- a/stgit/lib/git/repository.py +++ b/stgit/lib/git/repository.py @@ -163,15 +163,7 @@ class CatFileProcess: def _shutdown(self): if self._proc: - self._proc.stdin.close() - try: - os.kill(self._proc.pid(), signal.SIGTERM) - except OSError: - # There seems to be a race between the child process terminating due to - # its stdin being closed and the kill we attempt immediately thereafter. - # This is observed on Windows. - # Assume OSError indicates that the child process is already killed. - raise + os.kill(self._proc.pid(), signal.SIGTERM) self._proc.wait() def cat_file(self, sha1): -- 2.11.4.GIT