#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:\Python27\Scripts>python task_test.py
consumer before wait
consumer before wait
producer before notifyAll
producer after notifyAll
consumer after wait
consumer after wait

 

相关文章:

  • 2021-08-28
  • 2022-12-23
  • 2021-10-02
  • 2021-12-05
  • 2021-10-28
  • 2021-05-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-13
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案