4 Concurrent web requests
This chapter covers
- Asynchronous context managers
- Making asyncio-friendly web requests with aiohttp
- Running web requests concurrently with
gather
- Processing results as they come in with
as
completed
- Keeping track of in-flight requests with
wait
- Setting and handling timeouts for groups of requests and canceling requests
In chapter 3, we learned more about the inner workings of sockets and built a basic echo server. Now that we’ve seen how to design a basic application, we’ll take this knowledge and apply it to making concurrent, non-blocking web requests. Utilizing asyncio for web requests allows us to make hundreds of them at the same time, cutting down on our application’s runtime compared to a synchronous approach. ...
Get Python Concurrency with asyncio now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.