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 > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the functions of condition conditional variables in python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the functions of condition conditional 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 () so far, I believe you have a deeper understanding of "what is the role of condition condition variables in python". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.