python多进程数据共享Manager 中的BUG

# -*- 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)
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值