mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.11] gh-110036: multiprocessing Popen.terminate() catches PermissionError (GH-110037) (#110065)
gh-110036: multiprocessing Popen.terminate() catches PermissionError (GH-110037)
On Windows, multiprocessing Popen.terminate() now catchs
PermissionError and get the process exit code. If the process is
still running, raise again the PermissionError. Otherwise, the
process terminated as expected: store its exit code.
(cherry picked from commit bd4518c60c
)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
a99729599a
commit
efe83ad276
3 changed files with 17 additions and 4 deletions
|
@ -14,6 +14,7 @@ __all__ = ['Popen']
|
|||
#
|
||||
#
|
||||
|
||||
# Exit code used by Popen.terminate()
|
||||
TERMINATE = 0x10000
|
||||
WINEXE = (sys.platform == 'win32' and getattr(sys, 'frozen', False))
|
||||
WINSERVICE = sys.executable.lower().endswith("pythonservice.exe")
|
||||
|
@ -122,9 +123,15 @@ class Popen(object):
|
|||
if self.returncode is None:
|
||||
try:
|
||||
_winapi.TerminateProcess(int(self._handle), TERMINATE)
|
||||
except OSError:
|
||||
if self.wait(timeout=1.0) is None:
|
||||
except PermissionError:
|
||||
# ERROR_ACCESS_DENIED (winerror 5) is received when the
|
||||
# process already died.
|
||||
code = _winapi.GetExitCodeProcess(int(self._handle))
|
||||
if code == _winapi.STILL_ACTIVE:
|
||||
raise
|
||||
self.returncode = code
|
||||
else:
|
||||
self.returncode = -signal.SIGTERM
|
||||
|
||||
kill = terminate
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue