summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2022-05-01 23:09:50 (GMT)
committerGitHub <noreply@github.com>2022-05-01 23:09:50 (GMT)
commitea1eba03e7e8401d5acf8b30b56b41faa209e8c6 (patch)
tree21d81eb6e2a87a1853e2fea2cd5d295574a2ec7e /Lib/test/test_subprocess.py
parente7de54321952ebb58cc414f2160c9ad4f6510af2 (diff)
downloadcpython-ea1eba03e7e8401d5acf8b30b56b41faa209e8c6.zip
cpython-ea1eba03e7e8401d5acf8b30b56b41faa209e8c6.tar.gz
cpython-ea1eba03e7e8401d5acf8b30b56b41faa209e8c6.tar.bz2
[3.10] gh-91401: Conservative backport of `subprocess._USE_VFORK` (#91932)
This does not alter the `_posixsubprocess.fork_exec()` private API to avoid issues for anyone relying on that (bad idea) or for anyone who's `subprocess.py` and `_posixsubprocess.so` upgrades may not become visible to existing Python 3.10 processes at the same time. Backports the concept of cd5726fe674eaff442510eeb6c75628858be9e9f. Provides a fail-safe way to disable vfork for #91401. I didn't backport the documentation as I don't actually expect this to be used and `.. versionadded: 3.10.5` always looks weird in docs. It's being done more to have a fail-safe in place for people just in case.
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 7bb0492..b91791a 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1702,6 +1702,28 @@ class RunFuncTestCase(BaseTestCase):
msg="TimeoutExpired was delayed! Bad traceback:\n```\n"
f"{stacks}```")
+ @unittest.skipIf(not sysconfig.get_config_var("HAVE_VFORK"),
+ "vfork() not enabled by configure.")
+ def test__use_vfork(self):
+ # Attempts code coverage within _posixsubprocess.c on the code that
+ # probes the subprocess module for the existence and value of this
+ # attribute in 3.10.5.
+ self.assertTrue(subprocess._USE_VFORK) # The default value regardless.
+ with mock.patch.object(subprocess, "_USE_VFORK", False):
+ self.assertEqual(self.run_python("pass").returncode, 0,
+ msg="False _USE_VFORK failed")
+
+ class RaisingBool:
+ def __bool__(self):
+ raise RuntimeError("force PyObject_IsTrue to return -1")
+
+ with mock.patch.object(subprocess, "_USE_VFORK", RaisingBool()):
+ self.assertEqual(self.run_python("pass").returncode, 0,
+ msg="odd bool()-error _USE_VFORK failed")
+ del subprocess._USE_VFORK
+ self.assertEqual(self.run_python("pass").returncode, 0,
+ msg="lack of a _USE_VFORK attribute failed")
+
def _get_test_grp_name():
for name_group in ('staff', 'nogroup', 'grp', 'nobody', 'nfsnobody'):