# -*- coding: utf-8 -*-
from multiprocessing import Pool, Manager
#from multiprocessing.dummy import Pool
dst=['123','123','234']
shared_dict_count = Manager().dict()
shared_dict_wrong = Manager().dict()
shared_dict_count['math']=1
# shared_dict_count = {}
# shared_dict_wrong = {}
def post(dst):
for i in range(10):
print(i)
shared_dict_count['math']+=1
print('11111',shared_dict_count['math'])
if __name__ == "__main__":
pool = Pool(30)
r=pool.map(post, dst) #参数,迭代器
#pool.map(post, ['969.jpg'])
pool.close()
pool.join()
print('last',shared_dict_count['math'])
发现,进程池中同时跑三个进程,会发生堵塞,从而丢失。导致每次结果都不一样。
ocr@MEGVII1010525222:~/chenyu/ocr/EAST_keras$ python try2.py
0
0
0
1
1
2
2
1
3
3
4
4
2
5
5
3
6
6
4
7
7
5
8
6
8
9
7
9
('11111', 12)
8
('11111', 13)
9
('11111', 15)
('last', 15)