mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.11] gh-77377: Ensure multiprocessing SemLock is valid for spawn-based Process before serializing it (GH-107275) (#108378)
gh-77377: Ensure multiprocessing SemLock is valid for spawn-based Process before serializing it (GH-107275)
Ensure multiprocessing SemLock is valid for spawn Process before serializing it.
Creating a multiprocessing SemLock with a fork context, and then trying to pass it to a spawn-created Process, would segfault if not detected early.
---------
(cherry picked from commit 1700d34d31
)
Co-authored-by: albanD <desmaison.alban@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
This commit is contained in:
parent
93714b7db7
commit
34ef75d3ef
3 changed files with 30 additions and 2 deletions
|
@ -5345,6 +5345,28 @@ class TestStartMethod(unittest.TestCase):
|
|||
print(err)
|
||||
self.fail("failed spawning forkserver or grandchild")
|
||||
|
||||
@unittest.skipIf(sys.platform == "win32",
|
||||
"Only Spawn on windows so no risk of mixing")
|
||||
@only_run_in_spawn_testsuite("avoids redundant testing.")
|
||||
def test_mixed_startmethod(self):
|
||||
# Fork-based locks cannot be used with spawned process
|
||||
for process_method in ["spawn", "forkserver"]:
|
||||
queue = multiprocessing.get_context("fork").Queue()
|
||||
process_ctx = multiprocessing.get_context(process_method)
|
||||
p = process_ctx.Process(target=close_queue, args=(queue,))
|
||||
err_msg = "A SemLock created in a fork"
|
||||
with self.assertRaisesRegex(RuntimeError, err_msg):
|
||||
p.start()
|
||||
|
||||
# non-fork-based locks can be used with all other start methods
|
||||
for queue_method in ["spawn", "forkserver"]:
|
||||
for process_method in multiprocessing.get_all_start_methods():
|
||||
queue = multiprocessing.get_context(queue_method).Queue()
|
||||
process_ctx = multiprocessing.get_context(process_method)
|
||||
p = process_ctx.Process(target=close_queue, args=(queue,))
|
||||
p.start()
|
||||
p.join()
|
||||
|
||||
|
||||
@unittest.skipIf(sys.platform == "win32",
|
||||
"test semantics don't make sense on Windows")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue