久久久久久久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 與多處理一起使用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                只是實驗和學習,我知道如何創建一個可以通過多個進程訪問的共享字典,但我不確定如何保持字典同步.我相信 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中已經存在的屬性,可以使用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模板網!

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

                相關文檔推薦

                How to bind a function to an Action from Qt menubar?(如何將函數綁定到 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` 構造函數有未知關鍵字 `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'>

                          主站蜘蛛池模板: 精品视频免费 | 国产清纯白嫩初高生在线播放视频 | 黑人精品欧美一区二区蜜桃 | 一级高清 | 欧美成人手机视频 | 免费看国产一级特黄aaaa大片 | 国产中文字幕网 | 日韩三级一区 | 免费在线视频精品 | 九七午夜剧场福利写真 | 精品日韩欧美一区二区 | 免费在线观看一区二区三区 | av网站免费观看 | 国产精品国产三级国产aⅴ中文 | 懂色中文一区二区在线播放 | 成人免费xxxxx在线视频 | 91网站在线观看视频 | 久久久久久久一区 | 亚洲成人午夜电影 | 一区二区av | 欧美一区二区三区四区视频 | 91就要激情 | 午夜视频网站 | 欧美黑人激情 | 国产精品美女久久久久aⅴ国产馆 | 成人欧美一区二区三区色青冈 | 亚洲精品福利视频 | 成人午夜免费在线视频 | 精品国产乱码一区二区三区a | 老头搡老女人毛片视频在线看 | 免费视频一区二区三区在线观看 | 国产成人精品一区 | 免费一区| 天堂综合| 久草视频在线播放 | 日本高清在线一区 | 伊人免费在线 | 久久精品一区二区三区四区 | 久久精品综合网 | 一区二区蜜桃 | 国产探花|