Python Architecture (ii) __python

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.