Python Route 44-process and thread differences and Gil Global interpreter lock

Source: Internet
Author: User

Process

The program does not run alone, only the program is loaded into memory, the system allocates resources to run, and this execution of the program becomes a process, program and process differences, the program is a set of instructions, it is a static description of the process running text, process is a program execution activity, is a dynamic concept


Why do I have to thread the process?

Process can only do one thing at the same time

If the process is blocked during execution, such as waiting for input, the entire process hangs, even if some work in the process does not depend on this input data, it will not be able to execute


Thread

The line city is the smallest unit that the operating system can perform operation scheduling, which is contained in the process and is the actual running unit of the process.


The difference between a process and a thread

  1. Thread sharing creates its memory space for the process, and the process has its own independent memory space

  2. A thread can directly access the data segment of its process, and the process has its own copy of the data segment of the parent process

  3. Threads can communicate directly with other threads of their processes, and processes must communicate with sibling processes using interprocess communication

  4. Creating a thread is easy, and creating a process requires copying the parent process

  5. Changes to the main thread (cancellation, priority changes, etc.) may affect the behavior of other threads of the process, and changes to the parent process do not affect the child process


Gil Lock, Global interpreter lock

No matter how many threads are started, the computer has more than one cpu,python at the same time to allow only a single thread to run at the time of execution

The Gil is not a Python feature, it is a concept introduced when implementing the Python interpreter CPython

This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1907232

Python Route 44-process and thread differences and Gil Global interpreter lock

Related Article

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.