Neeraj's Blog

There is always an open source solution..

Python Run time structure

Actually all the complexities in running a python code is deliberately hidden from the programmers. We type code into text files, and run those files through the interpreter. But something more  is happening. The basic understanding of the run time structure of python can help to understand a detailed picture of program execution.

First the python script is compiled to byte code and then routed to a virtual machine.

Byte code compilation

Python first compiles the source code of the program to “byte  code“. Byte code is low level, platform independent representation of the source code. Byte code run more quickly than the source code. Python does not need to reanalyze and reparse each source statement repeatedly. The net effect is that pure Python code runs at speeds somewhere between those of a traditional compiled language and a traditional interpreted language. Python will store the byte code wit a .pyc (means compiled .py source) extension. When we run the source code for the second time, python will load the byte code, skips the compilation step unless we have not change the code.

Python Virtual Machine (PVM)

Once your byte code is formed, then it is carried to python virtual machine for execution. PVM is a big loop that iterates through the byte code instructions, one by one to carry out their operations. PVM is run time of engine of python. It is the component that actually runs the code.

Python’s traditional runtime execution model: source code you type is translated to byte code, which is then run by the Python Virtual Machine. Your code is automatically compiled, but then it is interpreted.

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: