Skip to product information
Digging into CPython
Digging into CPython
Description
Book Introduction
Understanding Python's internal workings at the interpreter level

Understanding how Python works at the interpreter level will help you take full advantage of its features and optimize your applications.
In "Uncovering CPython," we delve into the secrets of Python's inner workings and introduce how to compile source code into the Python interpreter.
This book explains the internal workings of Python components such as lists, dictionaries, and generators through practice problems to help you gain a deeper understanding of how Python actually works.
  • You can preview some of the book's contents.
    Preview

index
Chapter 1: Getting the CPython Source Code
1.1 What's included in the source code

Chapter 2: Setting up the development environment
2.1 Editor and Integrated Development Environment
2.2 Configuring Visual Studio
2.3 Configuring Visual Studio Code
-2.3.1 Installation
-2.3.2 Recommended Extensions
-2.3.3 Using advanced code navigation and expansion
-2.3.4 Setting up tasks and executables
2.4 Configuring JetBrains CLion
2.5 Configuring Vim
2.6 Summary

Chapter 3 Compiling CPython
3.1 Compiling CPython on macOS
3.2 Compiling CPython on Linux
3.3 Installing the Modified CPython
3.4 Introduction to make
3.5 CPython make targets
-3.5.1 build target
-3.5.2 Test Target
-3.5.3 Cleanup Target
-3.5.4 Other targets
3.6 Compiling CPython on Windows
-3.6.1 Installing dependencies
-3.6.2 Compiling from the command prompt
-3.6.3 Compiling in Visual Studio
3.7 Profile-based optimization
3.8 Summary

Chapter 4: Python Language and Grammar
4.1 Why CPython is written in C and not Python
4.2 Python Language Specification
-4.2.1 Python Language Reference
-4.2.2 Grammar File
4.3 Parser Generator
4.4 Regenerating the grammar
-4.4.1 Token
4.5 Summary

Chapter 5: Composition and Input
5.1 Configuration Status
-5.1.1 Dictionary Initialization Configuration
-5.1.2 List of associated source files
-5.1.3 Runtime Configuration Structure
-5.1.4 Setting the runtime configuration via the command line
-5.1.5 Checking runtime flags
5.2 Build Configuration
5.3 Creating a module from input
-5.3.1 List of associated source files
-5.3.2 Input and File Reading
-5.3.3 Enter command line string
-5.3.4 Local module input
-5.3.5 Standard input or script file input
-5.3.6 Input compiled bytecode
5.4 Summary

Chapter 6: Lexing and Parsing
6.1 Creating CST
6.2 Parser-Tokenizer
-6.2.1 List of associated source files
-6.2.2 Inputting file data into the parser
-6.2.3 Parser-tokenizer flow
6.3 Abstract Syntax Tree
-6.3.1 List of associated source files
-6.3.2 Visualizing AST with InstaVis
-6.3.3 AST compilation
6.4 Important Terms
6.5 Example: Adding the 'almost equal' comparison operator
6.6 Summary

Chapter 7 Compiler
7.1 Creating a Compiler Instance
7.2 Future Flags and Compiler Flags
-7.2.1 Future Flag
-7.2.2 List of future flags for Python 3.9
-7.2.3 Compiler Flags
7.3 Symbol Table
-7.3.1 List of associated source files
-7.3.2 Symbol Table Structure
-7.3.3 symtable module
-7.3.4 Symbol Table Implementation
7.4 Core Compilation Process
-7.4.1 Using the Compiler in Python
-7.4.2 Compiler C API
-7.4.3 command
-7.4.4 Basic Frame Block
-7.4.5 Commands and Arguments
7.5 Assembly
-7.5.1 Assembler Structures
-7.5.2 Depth-first search algorithm in assembler
-7.5.3 Assembler C API
-7.5.4 Depth-first search
7.6 Creating a Code Object
7.7 Visualizing Code Objects with InstaBiz
7.8 Example: Implementing the 'almost equal' operator
7.9 Summary

Chapter 8 Evaluation Loop
8.1 Creating a Thread State
-8.1.1 Thread State
-8.1.2 List of associated source files
8.2 Creating a Frame Object
-8.2.1 Frame Object
-8.2.2 List of associated source files
-8.2.3 Frame Object Initialization API
8.3 Frame Execution
-8.3.1 Frame Execution Tracing
8.4 Value Stack
-8.4.1 Example bytecode instruction: BINARY_OR
-8.4.2 Value Stack Simulation
-8.4.3 Stack Effect
8.5 Example: Adding an Element to a List
8.6 Summary

Chapter 9 Memory Management
9.1 Memory Allocation
-9.1.1 Static Memory Allocation
-9.1.2 Automatic memory allocation
-9.1.3 Dynamic Memory Allocation
9.2 Design of Python's Memory Management System
-9.2.1 Allocator Domain
-9.2.2 Memory Allocator
9.3 CPython Memory Allocator
-9.3.1 List of associated source files
-9.3.2 Important Terms
-9.3.3 Blocks, Pools, Arenas
-9.3.4 Block Allocation API
-9.3.5 Using the Python Debug API
9.4 Objects and the PyMem Memory Allocator Domain
-9.4.1 Using the tracemalloc module
9.5 Low-Level Memory Allocator Domain
9.6 Custom Domain Assigner
9.7 Custom Memory Allocation Checker
-9.7.1 AddressSanitizer
-9.7.2 MemorySanitizer
-9.7.3 UndefinedBehaviorSanitizer
9.8 PyArean Memory Arena
-9.8.1 List of associated files
9.9 Reference Counting
-9.9.1 Variable creation process in Python
-9.9.2 Incrementing the reference count
-9.9.3 Decrementing the reference count
-9.9.4 Reference Counting in Bytecode Operations
-9.9.5 Advantages of CPython Reference Counters
9.10 Garbage Collection
-9.10.1 List of associated source files
-9.10.2 Garbage Collector Design
-9.10.3 Container types eligible for garbage collection
-9.10.4 Objects and Variability That Can Be Excluded from Tracking
-9.10.5 Garbage Collection Algorithm
-9.10.6 Generational Garbage Collection
-9.10.7 Using the Garbage Collector API in Python
9/11 Summary

Chapter 10 Parallelism and Concurrency
10.1 Parallelism and Concurrency Models
10.2 Process Structure
10.3 Parallel execution using multiprocessing
-10.3.1 Forking Processes in POSIX
-10.3.2 Multiprocessing on Windows
-10.3.3 multiprocessing package
-10.3.4 List of associated source files
-10.3.5 Process Spawning and Forking
-10.3.6 Exchanging Data Using Queues and Pipes
-10.3.7 Shared state between processes
-10.3.8 Application Examples
-10.3.9 Multiprocessing Summary
10.4 Multithreading
-10.4.1 GIL
-10.4.2 List of associated source files
-10.4.3 Starting a Python Thread
-10.4.4 Thread Status
-10.4.5 POSIX Threads
-10.4.6 Windows Threads
-10.4.7 Multithreading Summary
10.5 Asynchronous Programming
10.6 Generator
-10.6.1 Generator Structure
-10.6.2 List of associated source files
-10.6.3 Creating a Generator
-10.6.4 Running the Generator
10.7 Coroutines
-10.7.1 List of associated source files
-10.7.2 Event Loop
-10.7.3 Example
10.8 Asynchronous Generators
10.9 Subinterpreters
-10.9.1 List of associated source files
-10.9.2 Example
10.10 Summary

Chapter 11 Objects and Types
11.1 Built-in types
11.2 Objects and Mutable Object Types
11.3 type type
-11.3.1 Type Slock
-11.3.2 Using Type C
-11.3.3 Type Property Dictionary
11.4 bool and long types
-11.4.1 long type
-11.4.2 Example
11.5 Unicode String Type
-11.5.1 List of associated source files
-11.5.2 Handling Unicode Code Points
-11.5.3 UTF-8 vs. UTF-16
-11.5.4 Wide character type
-11.5.5 Byte Order Mark
-11.5.6 encodings package
-11.5.7 Codec Module
-11.5.8 Codec implementation
-11.5.9 Internal Codec
-11.5.10 Example
11.6 Dictionary Types
-11.6.1 Hashing
-11.6.2 List of associated source files
-11.6.3 Dictionary Structure
-11.6.4 Search
11.7 Summary

Chapter 12 Standard Library
12.1 Python Modules
12.2 Modules that mix Python and C

Chapter 13 Test Suite
13.1 Running a Test Suite on Windows
13.2 Running Test Suites on Linux and macOS
13.3 Test Flags
13.4 Running only specific tests
13.5 Test Module
13.6 Test Utility
13.7 Summary

Chapter 14 Debugging
14.1 Crash Handler
14.2 Compiling with Debug Support
-14.2.1 Windows
-14.2.2 macOS or Linux
14.3 Using LLDB on macOS
-14.3.1 Adding a breakpoint
-14.3.2 Running CPython
-14.3.3 Connecting to a Running CPython Interpreter
-14.3.4 Using Breakpoints
-14.3.5 cpython_lldb extension
14.4 Using GDB
-14.4.1 Adding a breakpoint
-14.4.2 Running CPython
-14.4.3 Connecting to a Running CPython Interpreter
-14.4.4 Using Breakpoints
-14.4.5 pthon-gdb extension
14.5 Using the Visual Studio Debugger
-14.5.1 Adding a breakpoint
-14.5.2 Running the Debugger
-14.5.3 Using Breakpoints
14.6 Using the CLion Debugger
-14.6.1 Debugging Make Applications
-14.6.2 Connecting the Debugger
-14.6.3 Adding a breakpoint
-14.6.4 Using Breakpoints
14.7 Summary

Chapter 15: Benchmarking, Profiling, and Execution Tracing
15.1 Running micro-benchmarks with timeit
-15.1.1 timeit example
15.2 Running Runtime Benchmarks with the Python Benchmark Suite
-15.2.1 Running the Benchmark
-15.2.2 Comparing Benchmarks
15.3 Profiling Python Code with cProfile
-15.3.1 Exporting profile results
15.4 Profiling C Code with DTrace
-15.4.1 List of associated source files
-15.4.2 Installing DTrace
-15.4.3 Compiling with DTrace Support
-1.5.4.4 Using DTrace in CLion
-15.4.5 DTrace Example
15.5 Summary

Chapter 16: Next Steps
16.1 Writing C Extensions for CPython
16.2 Improving Python Applications
16.3 Contributing to the CPython Project
16.3.1 Categorizing Issues
16.3.2 Submitting a pull request to fix an issue
16.3.3 Contributing in Other Ways

Appendix A: A Python Programmer's Guide to C

Appendix B: The Future of CPython Through Performance Issues

Detailed image
Detailed Image 1

Publisher's Review
What this book covers
* Configuring the development environment
* Read and explore the source code
* Compiling CPython source code
* Understanding CPython memory management features
* Extending Python code with parallelism and concurrency
* Add new features to core types
* Running the test suite
* Debugging C and Python code
* Contribute to CPython

I recommend this book to anyone who wants to try 'hacking' CPython.
- Guido van Rossum, creator of Python

There are many books that teach the Python language itself, but there was no book that explained the internals of Python to the curious.
- Milan Patel, Vice President (Major Investment Bank)

This book provides essential information for anyone who wants to gain a deeper understanding of Python.
- Dan Bader, author of "Clever Python Tricks"
GOODS SPECIFICS
- Publication date: September 23, 2022
- Page count, weight, size: 364 pages | 610g | 172*225*18mm
- ISBN13: 9788966263677
- ISBN10: 8966263674

You may also like

카테고리