久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <i id='GObAm'><tr id='GObAm'><dt id='GObAm'><q id='GObAm'><span id='GObAm'><b id='GObAm'><form id='GObAm'><ins id='GObAm'></ins><ul id='GObAm'></ul><sub id='GObAm'></sub></form><legend id='GObAm'></legend><bdo id='GObAm'><pre id='GObAm'><center id='GObAm'></center></pre></bdo></b><th id='GObAm'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='GObAm'><tfoot id='GObAm'></tfoot><dl id='GObAm'><fieldset id='GObAm'></fieldset></dl></div>
  2. <legend id='GObAm'><style id='GObAm'><dir id='GObAm'><q id='GObAm'></q></dir></style></legend>

    <small id='GObAm'></small><noframes id='GObAm'>

      <tfoot id='GObAm'></tfoot>
      • <bdo id='GObAm'></bdo><ul id='GObAm'></ul>

      將 defaultdict 與多處理一起使用?

      Using defaultdict with multiprocessing?(將 defaultdict 與多處理一起使用?)
        <i id='RwlnS'><tr id='RwlnS'><dt id='RwlnS'><q id='RwlnS'><span id='RwlnS'><b id='RwlnS'><form id='RwlnS'><ins id='RwlnS'></ins><ul id='RwlnS'></ul><sub id='RwlnS'></sub></form><legend id='RwlnS'></legend><bdo id='RwlnS'><pre id='RwlnS'><center id='RwlnS'></center></pre></bdo></b><th id='RwlnS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RwlnS'><tfoot id='RwlnS'></tfoot><dl id='RwlnS'><fieldset id='RwlnS'></fieldset></dl></div>
          <tbody id='RwlnS'></tbody>

          <legend id='RwlnS'><style id='RwlnS'><dir id='RwlnS'><q id='RwlnS'></q></dir></style></legend>

            • <tfoot id='RwlnS'></tfoot>
              • <bdo id='RwlnS'></bdo><ul id='RwlnS'></ul>

                <small id='RwlnS'></small><noframes id='RwlnS'>

                本文介紹了將 defaultdict 與多處理一起使用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                只是實驗和學習,我知道如何創(chuàng)建一個可以通過多個進程訪問的共享字典,但我不確定如何保持字典同步.我相信 defaultdict 說明了我遇到的問題.

                Just experimenting and learning, and I know how to create a shared dictionary that can be accessed with multiple proceses but I'm not sure how to keep the dict synced. defaultdict, I believe, illustrates the problem I'm having.

                from collections import defaultdict
                from multiprocessing import Pool, Manager, Process
                
                #test without multiprocessing
                s = 'mississippi'
                d = defaultdict(int)
                for k in s:
                    d[k] += 1
                
                print d.items() # Success! result: [('i', 4), ('p', 2), ('s', 4), ('m', 1)]
                print '*'*10, ' with multiprocessing ', '*'*10
                
                def test(k, multi_dict):
                    multi_dict[k] += 1
                
                if __name__ == '__main__':
                    pool = Pool(processes=4)
                    mgr = Manager()
                    multi_d = mgr.dict()
                    for k in s:
                        pool.apply_async(test, (k, multi_d))
                
                    # Mark pool as closed -- no more tasks can be added.
                    pool.close()
                
                    # Wait for tasks to exit
                    pool.join()
                
                    # Output results
                    print multi_d.items()  #FAIL
                
                print '*'*10, ' with multiprocessing and process module like on python site example', '*'*10
                def test2(k, multi_dict2):
                    multi_dict2[k] += 1
                
                
                if __name__ == '__main__':
                    manager = Manager()
                
                    multi_d2 = manager.dict()
                    for k in s:
                        p = Process(target=test2, args=(k, multi_d2))
                    p.start()
                    p.join()
                
                    print multi_d2 #FAIL
                

                第一個結果有效(因為它不使用 multiprocessing),但我無法讓它與 multiprocessing 一起使用.我不知道如何解決它,但我認為可能是因為它沒有被同步(并在以后加入結果)或者可能是因為在 multiprocessing 我不知道如何設置 defaultdict(int) 到字典中.

                The first result works(because its not using multiprocessing), but I'm having problems getting it to work with multiprocessing. I'm not sure how to solve it but I think there might be due to it not being synced(and joining the results later) or maybe because within multiprocessing I cannot figure how to set defaultdict(int) to the dictionary.

                任何關于如何使它工作的幫助或建議都會很棒!

                Any help or suggestions on how to get this to work would be great!

                推薦答案

                您可以繼承 BaseManager 并注冊其他類型以進行共享.在默認 AutoProxy 生成的類型不起作用的情況下,您需要提供合適的代理類型.對于defaultdict,如果只需要訪問dict中已經(jīng)存在的屬性,可以使用DictProxy.

                You can subclass BaseManager and register additional types for sharing. You need to provide a suitable proxy type in cases where the default AutoProxy-generated type does not work. For defaultdict, if you only need to access the attributes that are already present in dict, you can use DictProxy.

                from multiprocessing import Pool
                from multiprocessing.managers import BaseManager, DictProxy
                from collections import defaultdict
                
                class MyManager(BaseManager):
                    pass
                
                MyManager.register('defaultdict', defaultdict, DictProxy)
                
                def test(k, multi_dict):
                    multi_dict[k] += 1
                
                if __name__ == '__main__':
                    pool = Pool(processes=4)
                    mgr = MyManager()
                    mgr.start()
                    multi_d = mgr.defaultdict(int)
                    for k in 'mississippi':
                        pool.apply_async(test, (k, multi_d))
                    pool.close()
                    pool.join()
                    print multi_d.items()
                

                這篇關于將 defaultdict 與多處理一起使用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                `QImage` constructor has unknown keyword `data`(`QImage` 構造函數(shù)有未知關鍵字 `data`)
                Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                  1. <i id='FZVFW'><tr id='FZVFW'><dt id='FZVFW'><q id='FZVFW'><span id='FZVFW'><b id='FZVFW'><form id='FZVFW'><ins id='FZVFW'></ins><ul id='FZVFW'></ul><sub id='FZVFW'></sub></form><legend id='FZVFW'></legend><bdo id='FZVFW'><pre id='FZVFW'><center id='FZVFW'></center></pre></bdo></b><th id='FZVFW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FZVFW'><tfoot id='FZVFW'></tfoot><dl id='FZVFW'><fieldset id='FZVFW'></fieldset></dl></div>
                      <tfoot id='FZVFW'></tfoot>

                          <tbody id='FZVFW'></tbody>

                          <bdo id='FZVFW'></bdo><ul id='FZVFW'></ul>
                          <legend id='FZVFW'><style id='FZVFW'><dir id='FZVFW'><q id='FZVFW'></q></dir></style></legend>

                          <small id='FZVFW'></small><noframes id='FZVFW'>

                          主站蜘蛛池模板: www.婷婷 | 成年人在线视频 | 污污的网站在线观看 | 国产视频1区 | 欧美一区二区三区在线看 | 欧美成人h版在线观看 | 日韩三 | 在线黄 | 91福利网| 欧美日韩三区 | 日韩欧美视频 | 日日操天天射 | 国产黄色精品在线观看 | 日韩欧美精品在线 | 国产剧情一区 | 国产一区| 暖暖成人免费视频 | 视频二区 | 免费国产一区二区 | 国产在线一区二区 | 第四色播日韩第一页 | 在线观看欧美日韩视频 | 欧美三级电影在线播放 | 韩日视频在线观看 | 精品久久久久久久久久久久 | 欧美一区二区 | 欧美精品一区在线 | 日韩精品在线看 | 欧美一区二区在线播放 | 成av人电影在线 | 日韩在线播放一区 | 丁香婷婷综合激情五月色 | 一区亚洲 | 91精品国产色综合久久不卡98 | 91精品综合久久久久久五月天 | 亚洲视频手机在线 | 亚洲一区三区在线观看 | 久久国产欧美一区二区三区精品 | 一区欧美 | 欧美国产91 | 一级特黄网站 |