Skip to content

Sending¤

Sender interface and related exceptions.

Senders¤

Messages are sent to a channel through Sender objects. Senders are usually created by calling channel.new_sender(), and are a very simple abstraction that only provides a single send() method:

await sender.send("Hello, world!")

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}")