Jason Brownlee's Blog, page 3
March 28, 2024
Asyncio TCP vs Unix Sockets
You can create TCP and Unix socket servers in asyncio programs. TCP sockets are suited for network applications, allowing connections from both local and remote clients. Unix sockets can be faster than TCP sockets, although are file-based and typically limited to client connections on one machine. In this tutorial, you will discover the difference between […]
Published on March 28, 2024 11:00
March 26, 2024
Asyncio Server Client Callback Handler
The asyncio server accepts client connections that call a custom client callback coroutine. Each time a client is connected to the asyncio server, the client callback coroutine is run in a new asyncio task and the task is not awaited by the server. This means that each client connection is isolated from the server. In […]
Published on March 26, 2024 11:00
March 24, 2024
Asyncio Server Context Manager
You can use the asyncio server asynchronous context manager by the “async with” expression. The context manager interface on the asyncio server will automatically close the server and all client connections. This is helpful to ensure that the server is closed safely, such as on error, when the server task is canceled, and when the […]
Published on March 24, 2024 11:00
March 21, 2024
How to Shutdown Asyncio Server Safely
You can run the asyncio server as a background task in an asyncio program. This has the benefit of allowing the main() coroutine to perform other tasks while the server is running and to cancel the server on demand if needed. The asyncio server will not close correctly if it is canceled. We can close […]
Published on March 21, 2024 11:00
March 19, 2024
Asyncio Socket Servers
We can create an asyncio server to accept and manage client socket connections. An asyncio server is not created directly, instead, we can use a factory function to configure, create, and start a socket server. We can then use the server or accept client connections forever. In this tutorial, you will discover how to create […]
Published on March 19, 2024 11:00
March 17, 2024
Asyncio Chat Client and Server
We can develop a group chat client and server with asyncio. A chat room allows multiple clients to connect to the same server and chat together. Each client message is transmitted to all connected clients. It is a great exercise in network programming and a great way to showcase asynchronous programming with asyncio with non-blocking […]
Published on March 17, 2024 11:00
March 14, 2024
Develop an Asyncio Echo Client and Server
You can develop an echo client and server using asyncio connections and streams. An echo server accepts client connections that send a message and reply with the same message, in turn, echoing it back. Developing an echo client and server is a common exercise in network programming. We can explore how to develop an echo […]
Published on March 14, 2024 11:00
March 12, 2024
Why Asyncio Task Never Runs and Completes
You can develop an asyncio program that schedules background tasks, but then never gives them an opportunity to run or complete. We can allow background tasks the opportunity to start running after they are scheduled by awaiting asyncio.sleep(0). We can also allow background tasks the opportunity to be completed without being canceled by awaiting them […]
Published on March 12, 2024 11:00
March 10, 2024
7 Common Asyncio Exceptions and Warnings
There are a series of common exceptions and warnings in asyncio, and we see most of them when we first get started developing asyncio programs. Knowing about them and how to fix them is important. In this tutorial, you will discover the 7 most common asyncio warnings and exceptions and how to avoid them. Let’s […]
Published on March 10, 2024 11:00
March 7, 2024
RuntimeError: cannot reuse already awaited coroutine
You will get a RuntimeError exception if you attempt to execute the same coroutine object more than once. The message of the exception will be “cannot reuse already awaited coroutine“. The RuntimeError exception occurs because we cannot execute the same coroutine object more than once, meaning we cannot await it more than once or schedule […]
Published on March 07, 2024 10:00


