zoukankan      html  css  js  c++  java
  • python进程同步,condition例子

    #coding=utf-8
    import multiprocessing as mp
    import time

    def consumer(cond):
        with cond:
            print "consumer before wait"
            cond.wait()
            print "consumer after wait"

    def producer(cond):
        with cond:
            print "producer before notifyAll"
            cond.notify_all()
            print "producer after notifyAll"

    if __name__ =='__main__':
        condition=mp.Condition()
       
        p1=mp.Process(name='p1',target=consumer,args=(condition,))
        p2=mp.Process(name='p2',target=consumer,args=(condition,))
        p3=mp.Process(name='p3',target=producer,args=(condition,))
       
        p1.start()
        time.sleep(2)
        p2.start()
        time.sleep(2)
        p3.start()
       

    c:Python27Scripts>python task_test.py
    consumer before wait
    consumer before wait
    producer before notifyAll
    producer after notifyAll
    consumer after wait
    consumer after wait

  • 相关阅读:
    Redux
    版本控制(.git + .svn + SourceTree)
    前端埋点
    前端IDE:VSCode + WebStorm
    浏览器
    Mutation Observer
    函数节流与函数去抖
    React 初识
    Ajax
    JS
  • 原文地址:https://www.cnblogs.com/xiaxiaoxu/p/8759355.html
Copyright © 2011-2022 走看看