CPython internals and the VM
summary
Shows CPython as a stack‑based VM: dis produces bytecode that pushes args, runs BINARY_ADD, stores and reloads values and returns; there is no optimization and no type info. The main loop lives in PyEval_EvalFrameEx and dispatches opcodes. Startup walks Modules/python.c → Py_Initialize → many PyType_Ready calls to init builtins, seeds hash randomization from /dev/urandom then a linear‑congruential RNG, and bootstraps user code via the runpy module ultimately invoked with PyObject_Call; a crafted test even causes a segfault at 87317 variables.
AI-written summary · about
chapters (14)
- 0:00Start
- 0:04Christopher Swenson
- 0:52What Happens When C Python Starts Up
- 3:03C Python Vm
- 7:39Main Loop
- 10:47Startup
- 11:46Hash Randomization
- 13:59Linear Congruential Random Number Generator
- 17:38Python Thread States
- 22:02Calculate the Method Resolution Order
- 24:02Checks for the Verbose Flag
- 25:36Run Module Main
- 29:13Reading the Python Code
- 31:16Pi Frame
related talks
50mExploring CPython's bytecode
32mBytecode and .pyc files
22mLow Level Python a Deep dive into the python sources
01h 21mExploring Python Code Objects
31mUnderstanding Python from the inside: C concepts to dive into CPython fearless
50mExploring CPython's bytecode
01h 03mA tour of CPython's runtime
17mInside a PyPy JIT: is that even legal?
