Python Global Interpreter Lock (GIL)

Source: Internet
Author: User
Gil should be a regular interview question, what is Gil? The Gil is the whole of global interpre lock (Universal interpreter lock). Not a Gil in Python, but a global interpreter lock in CPython. (No Gil in Jpython) The Gil is a mutex, CPython is not a thread-safe when executing multithreading, and the global interpreter lock is considered for the security of the program. Each CPU can only execute one thread at a time. Under Python multithreading, the execution of each thread requires a lock competition, and only the thread that gets the Gil can execute. Because of the Gil's existence, a process in Python can always execute only one thread at a time, which is why the multithreading efficiency of Python is not high on multicore CPUs. Because of the Gil, Python's multithreading is not friendly to CPU-intensive code, and is more friendly to IO-intensive code. 1 because of computationally intensive programs, you need to consume system resources. the existence of the Gil is equivalent to the constant single-threaded operation, which is slow. The reason why 2.IO-intensive has little effect, io,input/output, these two words indicate that the bottleneck of the program is the input
The time spent, the threads wait most of the time, so they are multiple together (multithreading) or single (single threaded) no matter
Multithreading is shared memory, which means that these threads share a single memory address. The advantage is that it facilitates data communication between threads
and data synchronization
Multi-process, each process address is a separate memory address. So there's no communication between addresses.

Python Global Interpreter Lock (GIL)

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.