1 #!/usr/bin/python 2 import multiprocessing,time 3 4 def A(cond): 5 name=multiprocessing.current_process().name 6 print "starting",name 7 with cond: 8 print "%s is done and next is ready"%name 9 cond.notify_all() 10 11 def B(cond): 12 name=multiprocessing.current_process().name 13 print "starting",name 14 with cond: 15 cond.wait() 16 print "%s running..."%name 17 18 cond=multiprocessing.Condition() 19 m=multiprocessing.Process(target=A,args=(cond,)) 20 n=[multiprocessing.Process(target=B,name="Process2[%d]"%i,args=(cond,)) for i in range(1,3)] 21 for i in n: 22 i.start() 23 time.sleep(2) 24 25 m.start() 26 m.join() 27 for i in n: 28 i.join()