diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-11 19:29:12 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-11 19:29:12 +0100 |
commit | f60845b70a78c0e29dc0e865c6cd9e2e35e635f5 (patch) | |
tree | 0e5bff369d2578750ed4a2e0be30cdae33fd9d8d /Lib/subprocess.py | |
parent | 5081957642caffae192b6e3f045a92b55afc8e9c (diff) | |
download | cpython-git-f60845b70a78c0e29dc0e865c6cd9e2e35e635f5.tar.gz |
Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under Windows when the child process has already exited.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index f0ef30e7fc..6cc3fa1312 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1016,7 +1016,17 @@ class Popen(object): def terminate(self): """Terminates the process """ - _subprocess.TerminateProcess(self._handle, 1) + try: + _subprocess.TerminateProcess(self._handle, 1) + except OSError as e: + # ERROR_ACCESS_DENIED (winerror 5) is received when the + # process already died. + if e.winerror != 5: + raise + rc = _subprocess.GetExitCodeProcess(self._handle) + if rc == _subprocess.STILL_ACTIVE: + raise + self.returncode = rc kill = terminate |