Skip to content

Commit 5bb1175

Browse files
[3.13] gh-121596: Fix Sharing Interpreter Channels (gh-121600)
This fixes a mistake in gh-113012 and adds a test that verifies the fix. (cherry picked from commit 35a67e3, AKA gh-121597) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
1 parent 85e9018 commit 5bb1175

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Lib/test/test_interpreters/test_channels.py

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_list_all(self):
4848
self.assertEqual(after, created)
4949

5050
def test_shareable(self):
51+
interp = interpreters.create()
5152
rch, sch = channels.create()
5253

5354
self.assertTrue(
@@ -60,8 +61,25 @@ def test_shareable(self):
6061
rch2 = rch.recv()
6162
sch2 = rch.recv()
6263

64+
interp.prepare_main(rch=rch, sch=sch)
65+
sch.send_nowait(rch)
66+
sch.send_nowait(sch)
67+
interp.exec(dedent("""
68+
rch2 = rch.recv()
69+
sch2 = rch.recv()
70+
assert rch2 == rch
71+
assert sch2 == sch
72+
73+
sch.send_nowait(rch2)
74+
sch.send_nowait(sch2)
75+
"""))
76+
rch3 = rch.recv()
77+
sch3 = rch.recv()
78+
6379
self.assertEqual(rch2, rch)
6480
self.assertEqual(sch2, sch)
81+
self.assertEqual(rch3, rch)
82+
self.assertEqual(sch3, sch)
6583

6684
def test_is_closed(self):
6785
rch, sch = channels.create()

Modules/_interpchannelsmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2615,10 +2615,10 @@ _get_current_channelend_type(int end)
26152615
}
26162616
if (cls == NULL) {
26172617
// Force the module to be loaded, to register the type.
2618-
PyObject *highlevel = PyImport_ImportModule("interpreters.channel");
2618+
PyObject *highlevel = PyImport_ImportModule("interpreters.channels");
26192619
if (highlevel == NULL) {
26202620
PyErr_Clear();
2621-
highlevel = PyImport_ImportModule("test.support.interpreters.channel");
2621+
highlevel = PyImport_ImportModule("test.support.interpreters.channels");
26222622
if (highlevel == NULL) {
26232623
return NULL;
26242624
}

0 commit comments

Comments
 (0)