Skip to content

Commit eb7f7eb

Browse files
Hide the channels module.
1 parent 226e75c commit eb7f7eb

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ Doc/howto/clinic.rst @erlend-aasland
284284
Lib/interpreters/ @ericsnowcurrently
285285
Modules/_interp*module.c @ericsnowcurrently
286286
Lib/test/test_interpreters/ @ericsnowcurrently
287+
Lib/test/test__interp*.py @ericsnowcurrently
288+
Lib/test/support/channels.py @ericsnowcurrently
289+
Lib/concurrent/futures/interpreter.py @ericsnowcurrently
290+
Doc/library/interpreters.rst @ericsnowcurrently
287291

288292
# Android
289293
**/*Android* @mhsmith @freakboy3742

Lib/interpreters/channels.py renamed to Lib/test/support/channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import time
44
import _interpchannels as _channels
5-
from . import _crossinterp
5+
from interpreters import _crossinterp
66

77
# aliases:
88
from _interpchannels import (
99
ChannelError, ChannelNotFoundError, ChannelClosedError, # noqa: F401
1010
ChannelEmptyError, ChannelNotEmptyError, # noqa: F401
1111
)
12-
from ._crossinterp import (
12+
from interpreters._crossinterp import (
1313
UNBOUND_ERROR, UNBOUND_REMOVE,
1414
)
1515

Lib/test/test_interpreters/test_channels.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Raise SkipTest if subinterpreters not supported.
1010
_channels = import_helper.import_module('_interpchannels')
1111
import interpreters
12-
from interpreters import channels
12+
from test.support import channels
1313
from .utils import _run_output, TestBase
1414

1515

@@ -171,7 +171,7 @@ def test_send_recv_main(self):
171171
def test_send_recv_same_interpreter(self):
172172
interp = interpreters.create()
173173
interp.exec(dedent("""
174-
from interpreters import channels
174+
from test.support import channels
175175
r, s = channels.create()
176176
orig = b'spam'
177177
s.send_nowait(orig)
@@ -244,7 +244,7 @@ def test_send_recv_nowait_main_with_default(self):
244244
def test_send_recv_nowait_same_interpreter(self):
245245
interp = interpreters.create()
246246
interp.exec(dedent("""
247-
from interpreters import channels
247+
from test.support import channels
248248
r, s = channels.create()
249249
orig = b'spam'
250250
s.send_nowait(orig)
@@ -387,7 +387,7 @@ def common(rch, sch, unbound=None, presize=0):
387387
interp = interpreters.create()
388388

389389
_run_output(interp, dedent(f"""
390-
from interpreters import channels
390+
from test.support import channels
391391
sch = channels.SendChannel({sch.id})
392392
obj1 = b'spam'
393393
obj2 = b'eggs'
@@ -482,7 +482,7 @@ def test_send_cleared_with_subinterpreter_mixed(self):
482482
self.assertEqual(_channels.get_count(rch.id), 0)
483483

484484
_run_output(interp, dedent(f"""
485-
from interpreters import channels
485+
from test.support import channels
486486
sch = channels.SendChannel({sch.id})
487487
sch.send_nowait(1, unbounditems=channels.UNBOUND)
488488
sch.send_nowait(2, unbounditems=channels.UNBOUND_ERROR)
@@ -518,15 +518,15 @@ def test_send_cleared_with_subinterpreter_multiple(self):
518518

519519
sch.send_nowait(1)
520520
_run_output(interp1, dedent(f"""
521-
from interpreters import channels
521+
from test.support import channels
522522
rch = channels.RecvChannel({rch.id})
523523
sch = channels.SendChannel({sch.id})
524524
obj1 = rch.recv()
525525
sch.send_nowait(2, unbounditems=channels.UNBOUND)
526526
sch.send_nowait(obj1, unbounditems=channels.UNBOUND_REMOVE)
527527
"""))
528528
_run_output(interp2, dedent(f"""
529-
from interpreters import channels
529+
from test.support import channels
530530
rch = channels.RecvChannel({rch.id})
531531
sch = channels.SendChannel({sch.id})
532532
obj2 = rch.recv()

Lib/test/test_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,12 +2516,12 @@ def setUpClass(cls):
25162516
import interpreters
25172517
except ModuleNotFoundError:
25182518
raise unittest.SkipTest('subinterpreters required')
2519-
import interpreters.channels # noqa: F401
2519+
import test.support.channels # noqa: F401
25202520

25212521
@cpython_only
25222522
@no_rerun('channels (and queues) might have a refleak; see gh-122199')
25232523
def test_static_types_inherited_slots(self):
2524-
rch, sch = interpreters.channels.create()
2524+
rch, sch = test.support.channels.create()
25252525

25262526
script = textwrap.dedent("""
25272527
import test.support

Modules/_interpchannelsmodule.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ wait_for_lock(PyThread_type_lock mutex, PY_TIMEOUT_T timeout)
220220
return 0;
221221
}
222222

223+
static int
224+
ensure_highlevel_module_loaded(void)
225+
{
226+
PyObject *highlevel = PyImport_ImportModule("interpreters.channels");
227+
if (highlevel == NULL) {
228+
PyErr_Clear();
229+
highlevel = PyImport_ImportModule("test.support.channels");
230+
if (highlevel == NULL) {
231+
return -1;
232+
}
233+
}
234+
Py_DECREF(highlevel);
235+
return 0;
236+
}
237+
223238

224239
/* module state *************************************************************/
225240

@@ -2742,11 +2757,9 @@ _get_current_channelend_type(int end)
27422757
}
27432758
if (cls == NULL) {
27442759
// Force the module to be loaded, to register the type.
2745-
PyObject *highlevel = PyImport_ImportModule("interpreters.channels");
2746-
if (highlevel == NULL) {
2760+
if (ensure_highlevel_module_loaded() < 0) {
27472761
return NULL;
27482762
}
2749-
Py_DECREF(highlevel);
27502763
if (end == CHANNEL_SEND) {
27512764
cls = state->send_channel_type;
27522765
}

0 commit comments

Comments
 (0)