]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-121596: Fix Sharing Interpreter Channels (gh-121600)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 10 Jul 2024 21:54:47 +0000 (23:54 +0200)
committerGitHub <noreply@github.com>
Wed, 10 Jul 2024 21:54:47 +0000 (21:54 +0000)
This fixes a mistake in gh-113012 and adds a test that verifies the fix.

(cherry picked from commit 35a67e36aa7cb0fc915771327f58bb0c70213867, AKA gh-121597)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Lib/test/test_interpreters/test_channels.py
Modules/_interpchannelsmodule.c

index 68cc45d1a5e09f89bd244a99380d9488b20d26a5..6c37754142e361ce7e5cfd0c60c03468a54679b2 100644 (file)
@@ -48,6 +48,7 @@ class TestChannels(TestBase):
         self.assertEqual(after, created)
 
     def test_shareable(self):
+        interp = interpreters.create()
         rch, sch = channels.create()
 
         self.assertTrue(
@@ -60,8 +61,25 @@ class TestChannels(TestBase):
         rch2 = rch.recv()
         sch2 = rch.recv()
 
+        interp.prepare_main(rch=rch, sch=sch)
+        sch.send_nowait(rch)
+        sch.send_nowait(sch)
+        interp.exec(dedent("""
+            rch2 = rch.recv()
+            sch2 = rch.recv()
+            assert rch2 == rch
+            assert sch2 == sch
+
+            sch.send_nowait(rch2)
+            sch.send_nowait(sch2)
+            """))
+        rch3 = rch.recv()
+        sch3 = rch.recv()
+
         self.assertEqual(rch2, rch)
         self.assertEqual(sch2, sch)
+        self.assertEqual(rch3, rch)
+        self.assertEqual(sch3, sch)
 
     def test_is_closed(self):
         rch, sch = channels.create()
index 47dbdeb9a37c444842559ab370bd402b3e1ea737..f0447475c49116c94dad18501b006b0bcff60279 100644 (file)
@@ -2615,10 +2615,10 @@ _get_current_channelend_type(int end)
     }
     if (cls == NULL) {
         // Force the module to be loaded, to register the type.
-        PyObject *highlevel = PyImport_ImportModule("interpreters.channel");
+        PyObject *highlevel = PyImport_ImportModule("interpreters.channels");
         if (highlevel == NULL) {
             PyErr_Clear();
-            highlevel = PyImport_ImportModule("test.support.interpreters.channel");
+            highlevel = PyImport_ImportModule("test.support.interpreters.channels");
             if (highlevel == NULL) {
                 return NULL;
             }