2
2
3
3
import time
4
4
import _xxsubinterpreters as _interpreters
5
+ import _xxinterpchannels as _channels
5
6
6
7
# aliases:
7
- from _xxsubinterpreters import (
8
+ from _xxsubinterpreters import is_shareable
9
+ from _xxinterpchannels import (
8
10
ChannelError , ChannelNotFoundError , ChannelEmptyError ,
9
- is_shareable ,
10
11
)
11
12
12
13
@@ -102,22 +103,22 @@ def create_channel():
102
103
103
104
The channel may be used to pass data safely between interpreters.
104
105
"""
105
- cid = _interpreters . channel_create ()
106
+ cid = _channels . create ()
106
107
recv , send = RecvChannel (cid ), SendChannel (cid )
107
108
return recv , send
108
109
109
110
110
111
def list_all_channels ():
111
112
"""Return a list of (recv, send) for all open channels."""
112
113
return [(RecvChannel (cid ), SendChannel (cid ))
113
- for cid in _interpreters . channel_list_all ()]
114
+ for cid in _channels . list_all ()]
114
115
115
116
116
117
class _ChannelEnd :
117
118
"""The base class for RecvChannel and SendChannel."""
118
119
119
120
def __init__ (self , id ):
120
- if not isinstance (id , (int , _interpreters .ChannelID )):
121
+ if not isinstance (id , (int , _channels .ChannelID )):
121
122
raise TypeError (f'id must be an int, got { id !r} ' )
122
123
self ._id = id
123
124
@@ -152,10 +153,10 @@ def recv(self, *, _sentinel=object(), _delay=10 / 1000): # 10 milliseconds
152
153
This blocks until an object has been sent, if none have been
153
154
sent already.
154
155
"""
155
- obj = _interpreters . channel_recv (self ._id , _sentinel )
156
+ obj = _channels . recv (self ._id , _sentinel )
156
157
while obj is _sentinel :
157
158
time .sleep (_delay )
158
- obj = _interpreters . channel_recv (self ._id , _sentinel )
159
+ obj = _channels . recv (self ._id , _sentinel )
159
160
return obj
160
161
161
162
def recv_nowait (self , default = _NOT_SET ):
@@ -166,9 +167,9 @@ def recv_nowait(self, default=_NOT_SET):
166
167
is the same as recv().
167
168
"""
168
169
if default is _NOT_SET :
169
- return _interpreters . channel_recv (self ._id )
170
+ return _channels . recv (self ._id )
170
171
else :
171
- return _interpreters . channel_recv (self ._id , default )
172
+ return _channels . recv (self ._id , default )
172
173
173
174
174
175
class SendChannel (_ChannelEnd ):
@@ -179,7 +180,7 @@ def send(self, obj):
179
180
180
181
This blocks until the object is received.
181
182
"""
182
- _interpreters . channel_send (self ._id , obj )
183
+ _channels . send (self ._id , obj )
183
184
# XXX We are missing a low-level channel_send_wait().
184
185
# See bpo-32604 and gh-19829.
185
186
# Until that shows up we fake it:
@@ -194,4 +195,4 @@ def send_nowait(self, obj):
194
195
# XXX Note that at the moment channel_send() only ever returns
195
196
# None. This should be fixed when channel_send_wait() is added.
196
197
# See bpo-32604 and gh-19829.
197
- return _interpreters . channel_send (self ._id , obj )
198
+ return _channels . send (self ._id , obj )
0 commit comments