mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
Fix subprocess.Popen.__del__() fox Python shutdown
Issue #29174, #26741: subprocess.Popen.__del__() now keeps a strong reference to warnings.warn() function.
This commit is contained in:
parent
94d1bfa2ef
commit
9505b03bb0
1 changed files with 3 additions and 3 deletions
|
|
@ -750,15 +750,15 @@ class Popen(object):
|
||||||
# Wait for the process to terminate, to avoid zombies.
|
# Wait for the process to terminate, to avoid zombies.
|
||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
def __del__(self, _maxsize=sys.maxsize):
|
def __del__(self, _maxsize=sys.maxsize, _warn=warnings.warn):
|
||||||
if not self._child_created:
|
if not self._child_created:
|
||||||
# We didn't get to successfully create a child process.
|
# We didn't get to successfully create a child process.
|
||||||
return
|
return
|
||||||
if self.returncode is None:
|
if self.returncode is None:
|
||||||
# Not reading subprocess exit status creates a zombi process which
|
# Not reading subprocess exit status creates a zombi process which
|
||||||
# is only destroyed at the parent python process exit
|
# is only destroyed at the parent python process exit
|
||||||
warnings.warn("subprocess %s is still running" % self.pid,
|
_warn("subprocess %s is still running" % self.pid,
|
||||||
ResourceWarning, source=self)
|
ResourceWarning, source=self)
|
||||||
# In case the child hasn't been waited on, check if it's done.
|
# In case the child hasn't been waited on, check if it's done.
|
||||||
self._internal_poll(_deadstate=_maxsize)
|
self._internal_poll(_deadstate=_maxsize)
|
||||||
if self.returncode is None and _active is not None:
|
if self.returncode is None and _active is not None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue