from multiprocessing import Process,Lock import os,time def walk(mutex): mutex.acquire() #为了防止偷看,记得上锁 print('task[%s] 洗澡'%os.getpid()) time.sleep(2) print('task[%s] 洗完澡'%os.getpid()) mutex.release() #洗完澡打开锁,难不成待一辈子 if __name__ == '__main__': mutex = Lock() p1 = Process(target=walk,args=(mutex,)) p2 = Process(target=walk,args=(mutex,)) p3 = Process(target=walk,args=(mutex,)) p1.start() p2.start() p3.start() print('this is father!!!!!!!!')