Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,8 @@ def __init__(self, args, bufsize=-1, executable=None,
else:
# POSIX
if pass_fds and not close_fds:
warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)
warnings.warn("pass_fds overriding close_fds.",
RuntimeWarning, stacklevel=2)
close_fds = True
if startupinfo is not None:
raise ValueError("startupinfo is only supported on Windows "
Expand Down Expand Up @@ -1567,7 +1568,8 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
if handle_list:
if not close_fds:
warnings.warn("startupinfo.lpAttributeList['handle_list'] "
"overriding close_fds", RuntimeWarning)
"overriding close_fds", RuntimeWarning,
stacklevel=3)

# When using the handle_list we always request to inherit
# handles but the only handles that will be inherited are
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3176,6 +3176,7 @@ def test_pass_fds(self):
ZERO_RETURN_CMD,
close_fds=False, pass_fds=(fd, )))
self.assertIn('overriding close_fds', str(context.warning))
self.assertEqual(context.filename, __file__)

def test_pass_fds_inheritable(self):
script = support.findfile("fd_status.py", subdir="subprocessdata")
Expand Down Expand Up @@ -3762,8 +3763,7 @@ def test_close_fds_with_stdio(self):
self.assertIn(b"OSError", stderr)

# Check for a warning due to using handle_list and close_fds=False
with warnings_helper.check_warnings((".*overriding close_fds",
RuntimeWarning)):
with self.assertWarns(RuntimeWarning) as cm:
startupinfo = subprocess.STARTUPINFO()
startupinfo.lpAttributeList = {"handle_list": handles[:]}
p = subprocess.Popen([sys.executable, "-c",
Expand All @@ -3772,6 +3772,8 @@ def test_close_fds_with_stdio(self):
startupinfo=startupinfo, close_fds=False)
stdout, stderr = p.communicate()
self.assertEqual(p.returncode, 0)
self.assertIn('overriding close_fds', str(cm.warning))
self.assertEqual(cm.filename, __file__)

def test_empty_attribute_list(self):
startupinfo = subprocess.STARTUPINFO()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Warnings emitted by :class:`subprocess.Popen` now correctly report the
caller's source location instead of a line inside :mod:`subprocess`.
Loading