#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