Skip to main content

8 docs tagged with "asyncio"

View all tags

Asynchronous File I/O: `aiofiles`

We've seen how asyncio is perfect for I/O-bound tasks and how aiohttp solves the problem of blocking network requests. But what about the other major type of I/O: reading and writing files?

Deadlocks and Best Practices in Asynchronous Python

This is the final article in our comprehensive series on asynchronous programming. We've learned how to create and run concurrent tasks, but with this power comes new challenges. One of the most notorious problems in any concurrent system is the deadlock.

Error Handling in Async Methods

Asynchronous programming introduces new complexities, and error handling is one of the most critical. When you are running dozens of tasks concurrently, what happens if one of them fails? How do you prevent a single failure from crashing your entire application?

Running Concurrent Tasks: `asyncio.gather()`

We've seen how to create individual tasks with asyncio.create_task() and then await them. This is a great way to start multiple background jobs. However, it can be a bit verbose if you just want to run a list of coroutines concurrently and wait for all of them to finish.

The `asyncio` Module: Event Loops, Coroutines, and Tasks

In our introduction to asynchronous programming, we saw how async and await can dramatically improve the performance of I/O-bound applications. Now, let's dive deeper into the three fundamental components that make this possible within the asyncio module: the Event Loop, Coroutines, and Tasks.

Working with Async HTTP Requests: `aiohttp`

The most common use case for asyncio is to handle I/O-bound tasks, and the most common I/O task in modern software is making network requests. However, the popular requests library is synchronous. If you use it in an async function, it will block the entire event loop, defeating the purpose of asyncio.