CPython Internals

CPython Internals

Anthony Shaw








Unlock the Inner Workings of the Python Language, Compile the Python Interpreter From Source Code,And Participate in the Development of CPython.

Anthony Shaw is an avid Pythonista and Fellow of the Python Software Foundation. Anthony has been programming since the age of 12 and found a love for Python while trapped inside a hotel in Seattle, Washington, 15 years later. After ditching the other languages he’d learned, Anthony has been researching, writing about, and creating courses for Python ever since. Anthony also co...

Chapter 1: Introduction How to make the most of this book so you can learn effectively and quickly get up to speed with CPython development.
Chapter 2: Getting the CPython Source Code The CPython source distribution comes with a whole range of tools, libraries, and components. You’ll start exploring them in this chapter.
Chapter 3: Setting Up Your Development Environment Throughout this book, you’ll be working with C and Python code. In this chapter you’ll see how to configure your development environment to support both languages.
Chapter 4: Compiling CPython Now that you have CPython downloaded, set up a development environment and configured it, you can compile the CPython source code into an executable interpreter.
Chapter 5: The Python Language and Grammar Understand why CPython is written in C and not Python and then dig into the Python Language Specification and it’s Parser Generator setup.

小众书,对 Python 的官方实现做了一个整体介绍,从词法、语法分析到编译器和字节码实现,代码解释执行以及多线程、异步执行等。内容很新(Py3.9),以实际代码为基础讲解,话题广泛,所以大部分地方都是点到为止。整体来说看过之后对以前只有模糊印象的东西有了稍微更深入的了解,比如 small object 的内存分配、多进程等并行执行的具体实现和机制等等,对想要去看 CPython 代码的人来说算是一个不错的整体索引。不过也有奇怪的地方,例如说 Python 的整数类型为了支持任意精度实际是存储的一个整数数组,例子里说比如 234 实际是存为 [2,3,4],不知道作者是打了一个很糟糕的比喻还是怎样,这个解释显然是不对的,如果这样的话又不禁让人疑问书里其他的地方是不是也有一些错漏和误解了。
倒是挺条理清晰的。比《Python源码剖析》好的地方是够新,用 py3.9 讲的。有些地方过于简略,用文字简要描述了下过程给个代码地址就过去了