Book description
Learn how to speed up slow Python code with concurrent programming and the cutting-edge asyncio library.- Use coroutines and tasks alongside async/await syntax to run code concurrently
- Build web APIs and make concurrency web requests with aiohttp
- Run thousands of SQL queries concurrently
- Create a map-reduce job that can process gigabytes of data concurrently
- Use threading with asyncio to mix blocking code with asyncio code
Python is flexible, versatile, and easy to learn. It can also be very slow compared to lower-level languages. Python Concurrency with asyncio teaches you how to boost Python's performance by applying a variety of concurrency techniques. You'll learn how the complex-but-powerful asyncio library can achieve concurrency with just a single thread and use asyncio's APIs to run multiple web requests and database queries simultaneously. The book covers using asyncio with the entire Python concurrency landscape, including multiprocessing and multithreading.
About the Technology
It’s easy to overload standard Python and watch your programs slow to a crawl. Th e asyncio library was built to solve these problems by making it easy to divide and schedule tasks. It seamlessly handles multiple operations concurrently, leading to apps that are lightning fast and scalable.
About the Book
Python Concurrency with asyncio introduces asynchronous, parallel, and concurrent programming through hands-on Python examples. Hard-to-grok concurrency topics are broken down into simple flowcharts that make it easy to see how your tasks are running. You’ll learn how to overcome the limitations of Python using asyncio to speed up slow web servers and microservices. You’ll even combine asyncio with traditional multiprocessing techniques for huge improvements to performance.
What's Inside
- Build web APIs and make concurrency web requests with aiohttp
- Run thousands of SQL queries concurrently
- Create a map-reduce job that can process gigabytes of data concurrently
- Use threading with asyncio to mix blocking code with asyncio code
About the Reader
For intermediate Python programmers. No previous experience of concurrency required.
About the Author
Matthew Fowler has over 15 years of software engineering experience in roles from architect to engineering director.
Quotes
A clear and practical guide to using asyncio to solve real-world concurrency problems.
- Didier Garcia, Software Sushi
Well organized and written…effectively guides the reader through a variety of impactful concurrency techniques.
- Dan Sheikh, BCG Digital Ventures
If you want to efficiently take your Python skills to the next level, look no further. This is the book for you.
- Eli Mayost, IBM
Provides a lot of insights into one of the trickier aspects of Python programming, namely asyncio.
- Peter White, Charles Sturt University
Table of contents
- inside front cover
- Python Concurrency with asyncio
- Copyright
- dedication
- contents
- front matter
-
1 Getting to know asyncio
- 1.1 What is asyncio?
- 1.2 What is I/O-bound and what is CPU-bound?
- 1.3 Understanding concurrency, parallelism, and multitasking
- 1.4 Understanding processes, threads, multithreading, and multiprocessing
- 1.5 Understanding the global interpreter lock
- 1.6 How single-threaded concurrency works
- 1.7 How an event loop works
- Summary
-
2 asyncio basics
- 2.1 Introducing coroutines
- 2.2 Introducing long-running coroutines with sleep
- 2.3 Running concurrently with tasks
- 2.4 Canceling tasks and setting timeouts
- 2.5 Tasks, coroutines, futures, and awaitables
- 2.6 Measuring coroutine execution time with decorators
- 2.7 The pitfalls of coroutines and tasks
- 2.8 Accessing and manually managing the event loop
- 2.9 Using debug mode
- Summary
- 3 A first asyncio application
- 4 Concurrent web requests
- 5 Non-blocking database drivers
- 6 Handling CPU-bound work
- 7 Handling blockingwork with threads
- 8 Streams
- 9 Web applications
- 10 Microservices
- 11 Synchronization
- 12 Asynchronous queues
- 13 Managing subprocesses
- 14 Advanced asyncio
- index
- inside back cover
Product information
- Title: Python Concurrency with asyncio
- Author(s):
- Release date: February 2022
- Publisher(s): Manning Publications
- ISBN: 9781617298660
You might also like
book
Mastering Concurrency in Python
Immerse yourself in the world of Python concurrency and tackle the most complex concurrent programming problems …
book
Using Asyncio in Python
If you’re among the Python developers put off by asyncio’s complexity, it’s time to take another …
book
Python for DevOps
Much has changed in technology over the past decade. Data is hot, the cloud is ubiquitous, …
book
Building Python Microservices with FastAPI
Discover the secrets of building Python microservices using the FastAPI framework Key Features Provides a reference …