thread 2

global interpreter

GIL: The essence is a mutual exclusion lock. Since it is a mutual exclusion lock, the essence of all mutual exclusion locks is the same. They all turn concurrent operation into serial, 
  so as to control that shared data can only be accessed by one task at the same time. modification to ensure data security.
1 GIL: The global interpreter lock
GIL is essentially a mutex lock, which is clamped on the interpreter.
All threads in the same process need to grab the GIL lock before executing the interpreter code

2. Advantages and disadvantages of GIL :
Advantages:
Ensure the thread safety of Cpython interpreter memory management

Disadvantages:
All threads in the same process can only have one execution at the same time, which
means that the multi-threading of the Cpython interpreter cannot realize the parallel

python interpreter
 for IO-intensive. Threads Multi-process thread mutex locks and GIL locks should be used   for computing-intensive types. GIL: GIL protects interpreter-level data, and users need to lock their own data to protect their own data. Mutex locks are: mutex locks are used for When a python file runs a process (thread), the competition for operations such as data modification becomes orderly. The process pool is different from the thread pool. 


  
  

The pool is used to limit the number of concurrent tasks, and limit our computer to execute tasks concurrently within a range that it can afford. When to install processes in the pool p=ThreadPoolExecutor (number of tasks) : Concurrent tasks belong to computationally intensive 
pools When to install threads: concurrent tasks are IO-intensive
1. Blocking and non-blocking refer to the two operating states of the program. 
  Blocking: Blocking occurs when IO is encountered. Once the program encounters a blocking operation, it will stop in place and immediately release CPU resources.
  Non-blocking (ready state or running state) : No IO operation is encountered, or by some means, the program will not stop in place even if it encounters an IO operation,
  perform other operations, and strive to occupy as much CPU as possible

2. Synchronization and asynchronous refer to the two aspects of submitting tasks. Method:
  Synchronous call: After submitting the task, wait in place, and continue to execute the next line of code until the return value of the task is obtained after the task is completed.
  Asynchronous call: After submitting the task, do not wait in place, execute directly Next line of code, result?
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324940558&siteId=291194637