Sending¤
Sender interface and related exceptions.
Senders¤
Messages are sent to a channel through
Sender objects. Senders
usually come from creating a channel, like a
BroadcastChannel, or from calling
sender.clone(). They are a very simple abstraction that mainly provides a
send() method:
Although send() is an asynchronous method, some
channels may implement it in a synchronous, non-blocking way. For example, buffered
channels that drop messages when the buffer is full could guarantee that
send() never blocks. However, please keep in mind
that the asyncio event loop could give control to another task at any time,
effectively making the send() method blocking.
Error Handling¤
Tip
For more information about handling errors, please refer to the Error Handling section of the user guide.
If there is any failure sending a message,
a SenderError exception is raised.
try:
await sender.send("Hello, world!")
except SenderError as error:
print(f"Error sending message: {error}")
Most errors mean that the sender, or its channel, can't be used anymore. A
TransientSenderError means that only
this message wasn't sent, and sending again later can work.