最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python基于event實(shí)現(xiàn)線程間通信控制

 更新時(shí)間:2020年01月13日 09:17:54   作者:Iceberg_710815  
這篇文章主要介紹了python基于event實(shí)現(xiàn)線程間通信控制,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了python基于event實(shí)現(xiàn)線程間通信控制,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

import threading,time
class Boss(threading.Thread):
  def run(self):
    print("We must work today!")
    event.isSet() or event.set()
    time.sleep(5)
    print("You can go home right now!")
    event.isSet() or event.set()

class Worker(threading.Thread):
  def run(self):
    event.wait()
    print("Oh,my god!!!")
    time.sleep(1)
    event.clear()
    event.wait()
    print("Oh,yeah!!!")
if __name__ == "__main__":
  event = threading.Event()
  threads = []
  for i in range(5):
    threads.append(Worker())
  threads.append(Boss())
  for t in threads:
    t.start()
  for t in threads:
    t.join()

運(yùn)行后顯示:

We must work today!
Oh,my god!!!
Oh,my god!!!
Oh,my god!!!
Oh,my god!!!
Oh,my god!!!
You can go home right now!
Oh,yeah!!!
Oh,yeah!!!
Oh,yeah!!!
Oh,yeah!!!
Oh,yeah!!!

Process finished with exit code 0

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

湟中县| 宁阳县| 禹城市| 宜昌市| 阳朔县| 合肥市| 江陵县| 南雄市| 开阳县| 滦平县| 文化| 黄平县| 合川市| 夏邑县| 巴彦县| 博白县| 莫力| 北碚区| 遂昌县| 伊金霍洛旗| 襄城县| 扶风县| 江门市| 蚌埠市| 红桥区| 汕尾市| 运城市| 广安市| 招远市| 隆德县| 永城市| 富宁县| 赞皇县| 自贡市| 丰原市| 泾川县| 安宁市| 嘉义县| 顺平县| 枞阳县| 嘉黎县|