Skip to Content
Intuitive Python
book

Intuitive Python

by David Muller
May 2021
Intermediate to advanced
142 pages
3h 37m
English
Pragmatic Bookshelf
Content preview from Intuitive Python

Approach Concurrency with Caution

Running your code concurrently sounds appealing—who doesn’t want to run more code? Unfortunately, running code concurrently can create problems that you didn’t realize even existed. Before diving into concurrency, we’ll start this chapter with a brief forewarning.

One class of problems caused by concurrency are called race conditions. In a classic race condition example, two concurrent banking operations accidentally allow a customer to overdraw his bank account:

  1. Customer David has $8 in his bank account.
  2. Process A reads David’s balance of $8.
  3. Process B reads David’s balance of $8.
  4. Process A allows David to withdraw $6.
  5. Process A updates David’s balance to $8 - $6 = $2.
  6. Process A ends.
  7. Process B allows David to withdraw ...
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

Pythonic Programming

Pythonic Programming

Dmitry Zinoviev
Python for Geeks

Python for Geeks

Muhammad Asif

Publisher Resources

ISBN: 9781680508635Errata Page