The sending end of a cross-interpreter channel.
| 179 | |
| 180 | |
| 181 | class SendChannel(_ChannelEnd): |
| 182 | """The sending end of a cross-interpreter channel.""" |
| 183 | |
| 184 | _end = 'send' |
| 185 | |
| 186 | # def __new__(cls, cid, *, _unbound=None): |
| 187 | # if _unbound is None: |
| 188 | # try: |
| 189 | # op = _channels.get_channel_defaults(cid) |
| 190 | # _unbound = (op,) |
| 191 | # except ChannelNotFoundError: |
| 192 | # _unbound = _serialize_unbound(UNBOUND) |
| 193 | # self = super().__new__(cls, cid) |
| 194 | # self._unbound = _unbound |
| 195 | # return self |
| 196 | |
| 197 | def _set_unbound(self, op, items=None): |
| 198 | assert not hasattr(self, '_unbound') |
| 199 | if items is None: |
| 200 | items = _resolve_unbound(op) |
| 201 | unbound = (op, items) |
| 202 | self._unbound = unbound |
| 203 | return unbound |
| 204 | |
| 205 | @property |
| 206 | def unbounditems(self): |
| 207 | try: |
| 208 | _, items = self._unbound |
| 209 | except AttributeError: |
| 210 | op, _ = _channels.get_queue_defaults(self._id) |
| 211 | _, items = self._set_unbound(op) |
| 212 | return items |
| 213 | |
| 214 | @property |
| 215 | def is_closed(self): |
| 216 | info = self._info |
| 217 | return info.closed or info.closing |
| 218 | |
| 219 | def send(self, obj, timeout=None, *, |
| 220 | unbounditems=None, |
| 221 | ): |
| 222 | """Send the object (i.e. its data) to the channel's receiving end. |
| 223 | |
| 224 | This blocks until the object is received. |
| 225 | """ |
| 226 | if unbounditems is None: |
| 227 | unboundop = -1 |
| 228 | else: |
| 229 | unboundop, = _serialize_unbound(unbounditems) |
| 230 | _channels.send(self._id, obj, unboundop, timeout=timeout, blocking=True) |
| 231 | |
| 232 | def send_nowait(self, obj, *, |
| 233 | unbounditems=None, |
| 234 | ): |
| 235 | """Send the object to the channel's receiving end. |
| 236 | |
| 237 | If the object is immediately received then return True |
| 238 | (else False). Otherwise this is the same as send(). |