import time
from multiprocessing import Process,Manager,Lock # a = 10
# # tmp = a
# # tmp -= 1
# # a = tmp
# a -= 1 # a = a - 1 def f1(m_d,l2):
# m_d['num'] -= 1 #
with l2:
# l2.acquire()
tmp = m_d['num']
tmp -= 1
time.sleep(0.1)
m_d['num'] = tmp
# l2.release() if __name__ == '__main__':
m = Manager()
l2 = Lock()
m_d = m.dict({'num':100})
p_list = []
for i in range(10):
p = Process(target=f1,args=(m_d,l2))
p.start()
p_list.append(p) [pp.join() for pp in p_list] print(m_d['num'])
相关文章
- 01-17数据库常见报错ORA-
- 01-17数据库系统原理——添加外键
- 01-17python 函数动态参数,名称空间,global,nonlocal
- 01-17获取当前 Python 版本
- 01-17【数据结构】可持久化线段树
- 01-17what's the python之函数及装饰器
- 01-17Python3 pip命令报错:Fatal error in launcher: Unable to create process using '"'
- 01-17[做题记录-数据结构] Luogu5210 [ZJOI2017]线段树
- 01-17使用NPOI和线程池快速加载EXCEL数据
- 01-17从shell(终端)中退出python