mirror of
https://github.com/python/cpython.git
synced 2025-10-01 04:42:10 +00:00
Fix issue #6973: When we know a subprocess.Popen process has died, do
not allow the send_signal(), terminate(), or kill() methods to do anything as they could potentially signal a different process.
This commit is contained in:
commit
97b0b1e8d4
2 changed files with 16 additions and 7 deletions
|
@ -1333,8 +1333,10 @@ class Popen(object):
|
||||||
return (stdout, stderr)
|
return (stdout, stderr)
|
||||||
|
|
||||||
def send_signal(self, sig):
|
def send_signal(self, sig):
|
||||||
"""Send a signal to the process
|
"""Send a signal to the process."""
|
||||||
"""
|
# Don't signal a process that we know has already died.
|
||||||
|
if self.returncode is not None:
|
||||||
|
return
|
||||||
if sig == signal.SIGTERM:
|
if sig == signal.SIGTERM:
|
||||||
self.terminate()
|
self.terminate()
|
||||||
elif sig == signal.CTRL_C_EVENT:
|
elif sig == signal.CTRL_C_EVENT:
|
||||||
|
@ -1345,8 +1347,10 @@ class Popen(object):
|
||||||
raise ValueError("Unsupported signal: {}".format(sig))
|
raise ValueError("Unsupported signal: {}".format(sig))
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
"""Terminates the process
|
"""Terminates the process."""
|
||||||
"""
|
# Don't terminate a process that we know has already died.
|
||||||
|
if self.returncode is not None:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
_winapi.TerminateProcess(self._handle, 1)
|
_winapi.TerminateProcess(self._handle, 1)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
|
@ -1754,8 +1758,9 @@ class Popen(object):
|
||||||
|
|
||||||
|
|
||||||
def send_signal(self, sig):
|
def send_signal(self, sig):
|
||||||
"""Send a signal to the process
|
"""Send a signal to the process."""
|
||||||
"""
|
# Skip signalling a process that we know has already died.
|
||||||
|
if self.returncode is None:
|
||||||
os.kill(self.pid, sig)
|
os.kill(self.pid, sig)
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
|
|
|
@ -88,6 +88,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #6973: When we know a subprocess.Popen process has died, do
|
||||||
|
not allow the send_signal(), terminate(), or kill() methods to do
|
||||||
|
anything as they could potentially signal a different process.
|
||||||
|
|
||||||
- Issue #23883: Added missing APIs to __all__ to match the documented APIs
|
- Issue #23883: Added missing APIs to __all__ to match the documented APIs
|
||||||
for the following modules: csv, enum, ftplib, logging, optparse, threading
|
for the following modules: csv, enum, ftplib, logging, optparse, threading
|
||||||
and wave. Also added a test.support.check__all__() helper. Patches by
|
and wave. Also added a test.support.check__all__() helper. Patches by
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue