Python进程锁的下面两种用法为什么在Windows系统中执行结果不一样????急!!!
第一段代码import multiprocessing
import time
lock = multiprocessing.Lock()
def fun():
lock.acquire()
for i in range(3):
time.sleep(0.5)
print(i)
lock.release()
return None
if __name__ == '__main__':
p1 = multiprocessing.Process(target=fun, args=())
p2 = multiprocessing.Process(target=fun, args=())
p1.start()
p2.start()
执行结果
0
0
1
1
2
2
第二段代码
import multiprocessing
import time
lock = multiprocessing.Lock()
def fun(lock):
lock.acquire()
for i in range(3):
time.sleep(0.5)
print(i)
lock.release()
return None
if __name__ == '__main__':
p1 = multiprocessing.Process(target=fun, args=(lock,))
p2 = multiprocessing.Process(target=fun, args=(lock,))
p1.start()
p2.start()
第二段代码执行结果
0
1
2
0
1
2