forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-98360: multiprocessing now spawns children on Windows with c…
…orrect argv[0] in virtual environments
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Windows/2022-10-19-20-00-28.gh-issue-98360.O2m6YG.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |