Python Interpreter Internals

Image result for Python Virtual Machine

Internals of Python Interpreter (VM):

  1. Python source code is compiled to byte code.
  2. Byte code is routed to virtual machine.

Byte Code Compilation:

from source code to byte code (instructions). Generating .pyc files if Python interpreter has write permissions otherwise, the byte code is generated in the memory and discarded on program exit.

The .pyc file contains 4 byte magic tag, 4 byte modification time stamp, and byte stream. Byte code is only saved for files that are imported.

Python checks time stamps of source code and byte code to know when it must recompile.

Python Virtual Machine:

Python virtual machine read both byte code and library modules to execute the code on the machine.

Python is dynamic typing, which means it determines data types on the runtime.

Reference:

https://cs263-technology-tutorial.readthedocs.io/en/latest/

www.devshed.com/c/a/python/how-python-runs-programs/