Python run-time Environment:
Python's runtime was initially created when the Python interpreter was started.
Create process: (1) Create main process object (pyinterpreterstate)
(2) Creating the main thread object (pythreadstate) and placing it in the Threaded object list (Tstate_head) of the main process object
(3) Create the System module: __builtin__ Module object, sys module object, exceptions Module object and __main__ module object, and put in the module object set modules of the main process object. In addition, a backup extensions of the module object is created, and the object created before it is backed up. (Note: The module object represents a Dictionary object Pydictobject in Python that contains several "name-object pointer" mappings to pair)
Once the runtime environment is created, it enters the interpretation execution phase.
Explain the execution process: (1) Compile the Python script and create the Code object (Pycodeobject), which contains the Python byte code directive.
(2) Create a Frame object (pyframeobject), place it into the Frame object list of the main thread object, set the code object, and set the global namespace (namespace) as the __main__ module object.
(3) begins executing the byte code instruction of the code object in the Frame object.
(4) After the execution, once the function call is found, a frame object is created, the Frame object list of the current thread object is added, initialized, and then the byte code instruction is executed.
Reference: "Python Source analysis-Deep exploration of dynamic language core technology"