MCPcopy
hub / github.com/python-trio/trio / send

Method send

src/trio/_channel.py:195–220  ·  view source on GitHub ↗

See `SendChannel.send `. Memory channels allow multiple tasks to call `send` at the same time.

(self, value: SendType)

Source from the content-addressed store, hash-verified

193
194 @enable_ki_protection
195 async def send(self, value: SendType) -> None:
196 """See `SendChannel.send <trio.abc.SendChannel.send>`.
197
198 Memory channels allow multiple tasks to call `send` at the same time.
199
200 """
201 await trio.lowlevel.checkpoint_if_cancelled()
202 try:
203 self.send_nowait(value)
204 except trio.WouldBlock:
205 pass
206 else:
207 await trio.lowlevel.cancel_shielded_checkpoint()
208 return
209
210 task = trio.lowlevel.current_task()
211 self._tasks.add(task)
212 self._state.send_tasks[task] = value
213 task.custom_sleep_data = self
214
215 def abort_fn(_: RaiseCancelT) -> Abort:
216 self._tasks.remove(task)
217 del self._state.send_tasks[task]
218 return trio.lowlevel.Abort.SUCCEEDED
219
220 await trio.lowlevel.wait_task_rescheduled(abort_fn)
221
222 # Return type must be stringified or use a TypeVar
223 @enable_ki_protection

Callers 1

_move_elems_to_channelFunction · 0.45

Calls 2

send_nowaitMethod · 0.95
addMethod · 0.80

Tested by

no test coverage detected