Skip to Content
Python Concurrency with asyncio
book

Python Concurrency with asyncio

by Matthew Fowler
February 2022
Intermediate to advanced
376 pages
10h 54m
English
Manning Publications
Content preview from Python Concurrency with asyncio

11 Synchronization

This chapter covers

  • Single-threaded concurrency issues
  • Using locks to protect critical sections
  • Using semaphores to limit concurrency
  • Using events to notify tasks
  • Using conditions to notify tasks and acquire a resource

When we write applications using multiple threads and multiple processes, we need to worry about race conditions when using non-atomic operations. Something as simple as incrementing an integer concurrently can cause subtle, hard-to-reproduce bugs. When we are using asyncio, however, we’re always using a single thread (unless we’re interoperating with multithreading and multiprocessing), so doesn’t that mean we don’t need to worry about race conditions? It turns out it is not quite so simple.

While certain ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken
Python for DevOps

Python for DevOps

Noah Gift, Kennedy Behrman, Alfredo Deza, Grig Gheorghiu

Publisher Resources

ISBN: 9781617298660Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentPurchase Link