import time
import threading
import multiprocessing
lock = multiprocessing.RLock()
def task(arg):
print('进程来了')
lock.acquire()
time.sleep(2)
print(arg)
lock.release()
if __name__ == '__main__':
p1 = multiprocessing.Process(target=task,args=(1,))
p1.start() p2 = multiprocessing.Process(target=task, args=(2,))
p2.start()

和线程锁一样,对照线程锁学习即可

05-11 09:23