liveBook · Manning

CPython

As explained in Python Concurrency with asyncio

The standard reference implementation of the Python programming language, written primarily in C.

CPython is Python’s standard reference implementation, written primarily in C. It defines expected language behavior and differs from alternatives such as Jython on the JVM and IronPython on .NET. section 1.5

CPython manages memory primarily through reference counting, but its implementation is not thread safe. The global interpreter lock (GIL) therefore permits only one thread in a process to execute Python bytecode at a time, even on multicore machines. section 1.5

This limits CPU-bound gains from multithreading and can expose shared-variable race conditions. Multiprocessing can execute bytecode concurrently because each process has its own GIL. section 1.5

Fibonacci and threads

Two recursive Fibonacci calculations complete in 65.1516 seconds sequentially and 66.1059 seconds with two threads, illustrating why threads do not automatically speed up CPU-bound Python work under CPython.

How Python Concurrency with asyncio covers it

How deep it goes
Explains reference counting, the GIL, race conditions, and timing evidence, but stops short of implementation-level internals.
Examples
Uses recursive Fibonacci timing and a reference-count race condition to demonstrate concurrency limits.
What you can do after
Evaluate/understand: Compare sequential and threaded CPU-bound work and recognize when multiprocessing is relevant.
How it connects
Connects CPython to the GIL, reference counting, multithreading, multiprocessing, race conditions, Jython, and IronPython.

Also explained in

Compare how 2 books explain CPython →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.