[3.12] gh-108520: Fix bad fork detection in nested multiprocessing use case (GH-108568) (#108691)

gh-108520: Fix bad fork detection in nested multiprocessing use case (GH-108568)

gh-107275 introduced a regression where a SemLock would fail being passed along nested child processes, as the `is_fork_ctx` attribute would be left missing after the first deserialization.

---------

(cherry picked from commit add8d45cbe)

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:
Miss Islington (bot) 2023-08-30 14:18:49 -07:00 committed by GitHub
parent 420db1027b
commit 320d398262
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View file

@ -5405,6 +5405,32 @@ class TestStartMethod(unittest.TestCase):
p.start()
p.join()
@classmethod
def _put_one_in_queue(cls, queue):
queue.put(1)
@classmethod
def _put_two_and_nest_once(cls, queue):
queue.put(2)
process = multiprocessing.Process(target=cls._put_one_in_queue, args=(queue,))
process.start()
process.join()
def test_nested_startmethod(self):
# gh-108520: Regression test to ensure that child process can send its
# arguments to another process
queue = multiprocessing.Queue()
process = multiprocessing.Process(target=self._put_two_and_nest_once, args=(queue,))
process.start()
process.join()
results = []
while not queue.empty():
results.append(queue.get())
self.assertEqual(results, [2, 1])
@unittest.skipIf(sys.platform == "win32",
"test semantics don't make sense on Windows")