Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the underlying principle of python GIL lock

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "what is the underlying principle of python GIL lock". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Analysis of the principle of releasing GIL Lock

1. Under single-core CPU, this situation is not particularly bad. Because there is only one CPU,CPU, the utilization is very high.

2. Under multi-core CPU, due to the overall characteristics of GIL lock, it can not play multi-core characteristics, GIL lock greatly reduces the efficiency of multi-threaded tasks.

Although all GIL locks are released, the two situations are different. For example, Thread1 encounters an IO operation to release GIL, and Thread2 and Thread3 compete for GIL locks, and Thread1 will no longer participate in this competition. If Thread1 releases GIL (mostly CPU-intensive tasks) because TimeTick expires, then three threads can compete for GIL locks at the same time, which may cause Thread1 to win the competition and re-execute.

There are two cases in which a thread releases an GIL lock

One is the IO operation, and the other is the TimeTick expiration. IO operations are easy to understand, such as making a http request and waiting for a response. So what is TimeTick expiration? TimeTick specifies the maximum execution time of the thread, after which the GIL lock is automatically released. After Python3, the interval is about 15 milliseconds.

What are the data types of python? the data types of python:

1. Numeric types, including int (integer), long (long integer), and float (floating point).

two。 String, which is of type str and type unicode, respectively.

3. Boolean, Python Boolean is also used for logical operations and has two values: True (true) and False (false).

4. List, the list is the most frequently used data type in Python, and any data type can be placed in the collection.

5. Tuples are identified by "()", and internal elements are separated by commas.

6. A dictionary is a collection of key-value pairs.

7. A collection is an unordered, non-repeating combination of data.

This is the end of the content of "what is the underlying principle of python GIL locks". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report