Condition in python multithreading

Thread blocking in python

Wait and notify these two methods, these two methods belong to the Condition class of threading, condition is a condition variable, which is used to control the synchronization between complex threads, each time the Condition() object is created internally and initialized. Lock, so as to ensure the security of the same object with;

wait() is very simple on the surface, that is, waiting, always blocking waiting for notification execution;

notify() is also very simple on the surface, that is, notify, notify blocking thread execution;

Purpose: In multithreading, realize read and write protection of global variables

usage:

import threading

from threading import Condition

condition = threading.Condition() # Create an object, the object created is different each time

 

with condition:

      condition.wait()

 

with condition:

     condition.notify()

 

Reference link 1

Reference link 2

Guess you like

Origin blog.csdn.net/Growing_hacker/article/details/103804634