Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9505b03

Browse files
committed
Fix subprocess.Popen.__del__() fox Python shutdown
Issue #29174, #26741: subprocess.Popen.__del__() now keeps a strong reference to warnings.warn() function.
1 parent 94d1bfa commit 9505b03

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/subprocess.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,15 +750,15 @@ def __exit__(self, type, value, traceback):
750750
# Wait for the process to terminate, to avoid zombies.
751751
self.wait()
752752

753-
def __del__(self, _maxsize=sys.maxsize):
753+
def __del__(self, _maxsize=sys.maxsize, _warn=warnings.warn):
754754
if not self._child_created:
755755
# We didn't get to successfully create a child process.
756756
return
757757
if self.returncode is None:
758758
# Not reading subprocess exit status creates a zombi process which
759759
# is only destroyed at the parent python process exit
760-
warnings.warn("subprocess %s is still running" % self.pid,
761-
ResourceWarning, source=self)
760+
_warn("subprocess %s is still running" % self.pid,
761+
ResourceWarning, source=self)
762762
# In case the child hasn't been waited on, check if it's done.
763763
self._internal_poll(_deadstate=_maxsize)
764764
if self.returncode is None and _active is not None:

0 commit comments

Comments
 (0)