CPython Internals: What Happens Before Bytecode Execution Starts
Learn about runtime initialization, parsing and compilation of the Python code into bytecode leading to execution on the virtual machine
This is a bonus part of the article on the design & implementation of the CPython virtual machine. In that article we discuss how the CPython virtual machine evaluates the bytecode to execute Python code. However, some details are skipped to limit the scope of the article. These include what happens when we start the Python process, and the flow of function calls that takes place to read the Python code, parse and compile it into bytecode instructions, and then finally prepare the stack frame which eventually is used by the VM to execute the bytecode. This article covers those missing details.