From 42aa3cc2bc3c81aa0057dacfdd9a2d344dc7b3cb Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 19 Oct 2022 20:01:06 +0100 Subject: [PATCH] gh-98360: multiprocessing now spawns children on Windows with correct argv[0] in virtual environments --- Lib/test/_test_venv_multiprocessing.py | 40 +++++++++++++++++++ ...2-10-19-20-00-28.gh-issue-98360.O2m6YG.rst | 4 ++ 2 files changed, 44 insertions(+) create mode 100644 Lib/test/_test_venv_multiprocessing.py create mode 100644 Misc/NEWS.d/next/Windows/2022-10-19-20-00-28.gh-issue-98360.O2m6YG.rst diff --git a/Lib/test/_test_venv_multiprocessing.py b/Lib/test/_test_venv_multiprocessing.py new file mode 100644 index 00000000000000..af72e915ba52bb --- /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/Misc/NEWS.d/next/Windows/2022-10-19-20-00-28.gh-issue-98360.O2m6YG.rst b/Misc/NEWS.d/next/Windows/2022-10-19-20-00-28.gh-issue-98360.O2m6YG.rst new file mode 100644 index 00000000000000..61c1e5e837fe3e --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2022-10-19-20-00-28.gh-issue-98360.O2m6YG.rst @@ -0,0 +1,4 @@ +Fixes :mod:`multiprocessing` spawning child processes on Windows from a +virtual environment to ensure that child processes that also use +:mod:`multiprocessing` to spawn more children will recognize that they are +in a virtual environment.