22
33import time
44import _xxsubinterpreters as _interpreters
5+ import _xxinterpchannels as _channels
56
67# aliases:
7- from _xxsubinterpreters import (
8+ from _xxsubinterpreters import is_shareable
9+ from _xxinterpchannels import (
810 ChannelError , ChannelNotFoundError , ChannelEmptyError ,
9- is_shareable ,
1011)
1112
1213
@@ -102,22 +103,22 @@ def create_channel():
102103
103104 The channel may be used to pass data safely between interpreters.
104105 """
105- cid = _interpreters . channel_create ()
106+ cid = _channels . create ()
106107 recv , send = RecvChannel (cid ), SendChannel (cid )
107108 return recv , send
108109
109110
110111def list_all_channels ():
111112 """Return a list of (recv, send) for all open channels."""
112113 return [(RecvChannel (cid ), SendChannel (cid ))
113- for cid in _interpreters . channel_list_all ()]
114+ for cid in _channels . list_all ()]
114115
115116
116117class _ChannelEnd :
117118 """The base class for RecvChannel and SendChannel."""
118119
119120 def __init__ (self , id ):
120- if not isinstance (id , (int , _interpreters .ChannelID )):
121+ if not isinstance (id , (int , _channels .ChannelID )):
121122 raise TypeError (f'id must be an int, got { id !r} ' )
122123 self ._id = id
123124
@@ -152,10 +153,10 @@ def recv(self, *, _sentinel=object(), _delay=10 / 1000): # 10 milliseconds
152153 This blocks until an object has been sent, if none have been
153154 sent already.
154155 """
155- obj = _interpreters . channel_recv (self ._id , _sentinel )
156+ obj = _channels . recv (self ._id , _sentinel )
156157 while obj is _sentinel :
157158 time .sleep (_delay )
158- obj = _interpreters . channel_recv (self ._id , _sentinel )
159+ obj = _channels . recv (self ._id , _sentinel )
159160 return obj
160161
161162 def recv_nowait (self , default = _NOT_SET ):
@@ -166,9 +167,9 @@ def recv_nowait(self, default=_NOT_SET):
166167 is the same as recv().
167168 """
168169 if default is _NOT_SET :
169- return _interpreters . channel_recv (self ._id )
170+ return _channels . recv (self ._id )
170171 else :
171- return _interpreters . channel_recv (self ._id , default )
172+ return _channels . recv (self ._id , default )
172173
173174
174175class SendChannel (_ChannelEnd ):
@@ -179,7 +180,7 @@ def send(self, obj):
179180
180181 This blocks until the object is received.
181182 """
182- _interpreters . channel_send (self ._id , obj )
183+ _channels . send (self ._id , obj )
183184 # XXX We are missing a low-level channel_send_wait().
184185 # See bpo-32604 and gh-19829.
185186 # Until that shows up we fake it:
@@ -194,4 +195,4 @@ def send_nowait(self, obj):
194195 # XXX Note that at the moment channel_send() only ever returns
195196 # None. This should be fixed when channel_send_wait() is added.
196197 # See bpo-32604 and gh-19829.
197- return _interpreters . channel_send (self ._id , obj )
198+ return _channels . send (self ._id , obj )
0 commit comments