diff options
author | Steve Dower <steve.dower@python.org> | 2022-10-20 13:53:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 13:53:38 (GMT) |
commit | e48f9b2b7e73f4a89a9b9c287f3b93dc13a60460 (patch) | |
tree | 31dfc7cb8b10e661fb2b7ca1a608fce98f130884 /Lib/test | |
parent | cb93b4aee5eb12dc6c4b2dccc81a2e5ace3ea4de (diff) | |
download | cpython-e48f9b2b7e73f4a89a9b9c287f3b93dc13a60460.zip cpython-e48f9b2b7e73f4a89a9b9c287f3b93dc13a60460.tar.gz cpython-e48f9b2b7e73f4a89a9b9c287f3b93dc13a60460.tar.bz2 |
gh-98360: multiprocessing now spawns children on Windows with correct argv[0] in virtual environments (GH-98462)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/_test_venv_multiprocessing.py | 40 | ||||
-rw-r--r-- | Lib/test/test_venv.py | 16 |
2 files changed, 55 insertions, 1 deletions
diff --git a/Lib/test/_test_venv_multiprocessing.py b/Lib/test/_test_venv_multiprocessing.py new file mode 100644 index 0000000..af72e91 --- /dev/null +++ b/Lib/test/_test_venv_multiprocessing.py @@ -0,0 +1,40 @@ +import multiprocessing +import random +import sys +import time + +def fill_queue(queue, code): + queue.put(code) + + +def drain_queue(queue, code): + if code != queue.get(): + sys.exit(1) + + +def test_func(): + code = random.randrange(0, 1000) + queue = multiprocessing.Queue() + fill_pool = multiprocessing.Process( + target=fill_queue, + args=(queue, code) + ) + drain_pool = multiprocessing.Process( + target=drain_queue, + args=(queue, code) + ) + drain_pool.start() + fill_pool.start() + fill_pool.join() + drain_pool.join() + + +def main(): + test_pool = multiprocessing.Process(target=test_func) + test_pool.start() + test_pool.join() + sys.exit(test_pool.exitcode) + + +if __name__ == "__main__": + main() diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index b355b00..5ce86cf 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -20,7 +20,7 @@ import tempfile from test.support import (captured_stdout, captured_stderr, skip_if_broken_multiprocessing_synchronize, verbose, requires_subprocess, is_emscripten, is_wasi, - requires_venv_with_pip) + requires_venv_with_pip, TEST_HOME_DIR) from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree) import unittest import venv @@ -482,6 +482,20 @@ class BasicTest(BaseTest): 'pool.terminate()']) self.assertEqual(out.strip(), "python".encode()) + @requireVenvCreate + def test_multiprocessing_recursion(self): + """ + Test that the multiprocessing is able to spawn itself + """ + skip_if_broken_multiprocessing_synchronize() + + rmtree(self.env_dir) + self.run_with_capture(venv.create, self.env_dir) + envpy = os.path.join(os.path.realpath(self.env_dir), + self.bindir, self.exe) + script = os.path.join(TEST_HOME_DIR, '_test_venv_multiprocessing.py') + subprocess.check_call([envpy, script]) + @unittest.skipIf(os.name == 'nt', 'not relevant on Windows') def test_deactivate_with_strict_bash_opts(self): bash = shutil.which("bash") |