In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what is the role of condition condition variables in python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of condition condition variables in python".
1. The Condition object provided by Python supports complex thread synchronization.
2. Condition is called a conditional variable, which provides wait and notify methods in addition to acquire and release methods similar to Lock. The thread first acquire the condition variable, and then judges some conditions.
Example
Import threading, timeclass Hider (threading.Thread): def _ _ init__ (self, cond, name): super (Hider Self). _ init__ () self.cond = cond self.name = name def run (self): time.sleep (1) # make sure to run the method in Seeker self.cond.acquire () # b print (self.name +': I have been blindfolded') self.cond.notify () self.cond.wait () # c # f print (self.name +': I found you ~ ~') # self.cond.notify () self.cond.release () # g print (self.name +': I won') # hclass Seeker (threading.Thread): def _ _ init__ (self) Cond, name): super (Seeker, self). _ _ init__ () self.cond = cond self.name = name def run (self): self.cond.acquire () self.cond.wait () # a # release trivial occupation At the same time the thread is suspended here until it is notify and repossessed. # d print (self.name +': I have hidden it, please come and find me') self.cond.notify () self.cond.wait () # e # h self.cond.release () print (self.name +': you found it Hey ~ ~') cond = threading.Condition () seeker = Seeker (cond, 'seeker') hider = Hider (cond,' hider') seeker.start () hider.start () Thank you for your reading, the above is the content of "what is the role of condition condition variables in python". After the study of this article, I believe you have a deeper understanding of the role of condition condition variables in python, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.