diff options
author | chgnrdv <52372310+chgnrdv@users.noreply.github.com> | 2023-06-04 07:06:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-04 04:06:45 +0000 |
commit | ce558e69d4087dd3653207de78345fbb8a2c7835 (patch) | |
tree | a96a5b705ac12fced6d95ca55787d270550edbf8 /Lib/test/test_subprocess.py | |
parent | eaff9c39aa1a70d401521847cc35bec883ae9772 (diff) | |
download | cpython-ce558e69d4087dd3653207de78345fbb8a2c7835.tar.gz cpython-ce558e69d4087dd3653207de78345fbb8a2c7835.zip |
gh-104690 Disallow thread creation and fork at interpreter finalization (#104826)
Disallow thread creation and fork at interpreter finalization.
in the following functions, check if interpreter is finalizing and raise `RuntimeError` with appropriate message:
* `_thread.start_new_thread` and thus `threading`
* `posix.fork`
* `posix.fork1`
* `posix.forkpty`
* `_posixsubprocess.fork_exec` when a `preexec_fn=` is supplied.
---------
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r-- | Lib/test/test_subprocess.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 92f81eaafb1..51ba423a0f1 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -5,6 +5,7 @@ from test.support import check_sanitizer from test.support import import_helper from test.support import os_helper from test.support import warnings_helper +from test.support.script_helper import assert_python_ok import subprocess import sys import signal @@ -3329,6 +3330,24 @@ class POSIXProcessTestCase(BaseTestCase): except subprocess.TimeoutExpired: pass + def test_preexec_at_exit(self): + code = f"""if 1: + import atexit + import subprocess + + def dummy(): + pass + + def exit_handler(): + subprocess.Popen({ZERO_RETURN_CMD}, preexec_fn=dummy) + print("shouldn't be printed") + + atexit.register(exit_handler) + """ + _, out, err = assert_python_ok("-c", code) + self.assertEqual(out, b'') + self.assertIn(b"preexec_fn not supported at interpreter shutdown", err) + @unittest.skipUnless(mswindows, "Windows specific tests") class Win32ProcessTestCase(BaseTestCase): |