Skip to content

Commit

Permalink
Fix test.support.interpreters.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Feb 3, 2023
1 parent 2afbdc6 commit ea0394c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 12 additions & 11 deletions Lib/test/support/interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import time
import _xxsubinterpreters as _interpreters
import _xxinterpchannels as _channels

# aliases:
from _xxsubinterpreters import (
from _xxsubinterpreters import is_shareable
from _xxinterpchannels import (
ChannelError, ChannelNotFoundError, ChannelEmptyError,
is_shareable,
)


Expand Down Expand Up @@ -102,22 +103,22 @@ def create_channel():
The channel may be used to pass data safely between interpreters.
"""
cid = _interpreters.channel_create()
cid = _channels.create()
recv, send = RecvChannel(cid), SendChannel(cid)
return recv, send


def list_all_channels():
"""Return a list of (recv, send) for all open channels."""
return [(RecvChannel(cid), SendChannel(cid))
for cid in _interpreters.channel_list_all()]
for cid in _channels.list_all()]


class _ChannelEnd:
"""The base class for RecvChannel and SendChannel."""

def __init__(self, id):
if not isinstance(id, (int, _interpreters.ChannelID)):
if not isinstance(id, (int, _channels.ChannelID)):
raise TypeError(f'id must be an int, got {id!r}')
self._id = id

Expand Down Expand Up @@ -152,10 +153,10 @@ def recv(self, *, _sentinel=object(), _delay=10 / 1000): # 10 milliseconds
This blocks until an object has been sent, if none have been
sent already.
"""
obj = _interpreters.channel_recv(self._id, _sentinel)
obj = _channels.recv(self._id, _sentinel)
while obj is _sentinel:
time.sleep(_delay)
obj = _interpreters.channel_recv(self._id, _sentinel)
obj = _channels.recv(self._id, _sentinel)
return obj

def recv_nowait(self, default=_NOT_SET):
Expand All @@ -166,9 +167,9 @@ def recv_nowait(self, default=_NOT_SET):
is the same as recv().
"""
if default is _NOT_SET:
return _interpreters.channel_recv(self._id)
return _channels.recv(self._id)
else:
return _interpreters.channel_recv(self._id, default)
return _channels.recv(self._id, default)


class SendChannel(_ChannelEnd):
Expand All @@ -179,7 +180,7 @@ def send(self, obj):
This blocks until the object is received.
"""
_interpreters.channel_send(self._id, obj)
_channels.send(self._id, obj)
# XXX We are missing a low-level channel_send_wait().
# See bpo-32604 and gh-19829.
# Until that shows up we fake it:
Expand All @@ -194,4 +195,4 @@ def send_nowait(self, obj):
# XXX Note that at the moment channel_send() only ever returns
# None. This should be fixed when channel_send_wait() is added.
# See bpo-32604 and gh-19829.
return _interpreters.channel_send(self._id, obj)
return _channels.send(self._id, obj)
5 changes: 3 additions & 2 deletions Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from test import support
from test.support import import_helper
_interpreters = import_helper.import_module('_xxsubinterpreters')
_channels = import_helper.import_module('_xxinterpchannels')
from test.support import interpreters


Expand Down Expand Up @@ -533,7 +534,7 @@ class TestRecvChannelAttrs(TestBase):

def test_id_type(self):
rch, _ = interpreters.create_channel()
self.assertIsInstance(rch.id, _interpreters.ChannelID)
self.assertIsInstance(rch.id, _channels.ChannelID)

def test_custom_id(self):
rch = interpreters.RecvChannel(1)
Expand All @@ -558,7 +559,7 @@ class TestSendChannelAttrs(TestBase):

def test_id_type(self):
_, sch = interpreters.create_channel()
self.assertIsInstance(sch.id, _interpreters.ChannelID)
self.assertIsInstance(sch.id, _channels.ChannelID)

def test_custom_id(self):
sch = interpreters.SendChannel(1)
Expand Down

0 comments on commit ea0394c

Please sign in to comment.