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

    1. <small id='Y7gQR'></small><noframes id='Y7gQR'>

        <tfoot id='Y7gQR'></tfoot>

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

        如何在導入的模塊中使用 multiprocessing.Pool?

        How to use multiprocessing.Pool in an imported module?(如何在導入的模塊中使用 multiprocessing.Pool?)
        <legend id='wVN80'><style id='wVN80'><dir id='wVN80'><q id='wVN80'></q></dir></style></legend>
            <tbody id='wVN80'></tbody>
            <bdo id='wVN80'></bdo><ul id='wVN80'></ul>
            • <i id='wVN80'><tr id='wVN80'><dt id='wVN80'><q id='wVN80'><span id='wVN80'><b id='wVN80'><form id='wVN80'><ins id='wVN80'></ins><ul id='wVN80'></ul><sub id='wVN80'></sub></form><legend id='wVN80'></legend><bdo id='wVN80'><pre id='wVN80'><center id='wVN80'></center></pre></bdo></b><th id='wVN80'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wVN80'><tfoot id='wVN80'></tfoot><dl id='wVN80'><fieldset id='wVN80'></fieldset></dl></div>

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

                <tfoot id='wVN80'></tfoot>

                  本文介紹了如何在導入的模塊中使用 multiprocessing.Pool?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我無法在這里實施建議:同時對兩個列表應用兩個函數.

                  I have not been able to implement the suggestion here: Applying two functions to two lists simultaneously.

                  我猜是因為該模塊是由另一個模塊導入的,因此我的 Windows 產生了多個 python 進程?

                  I guess it is because the module is imported by another module and thus my Windows spawns multiple python processes?

                  我的問題是:我如何在沒有 if if __name__ == "__main__":

                  My question is: how can I use the code below without the if if __name__ == "__main__":

                  args_m = [(mortality_men, my_agents, graveyard, families, firms, year, agent) for agent in males]
                  args_f = [(mortality_women, fertility, year, families, my_agents, graveyard, firms, agent) for agent in females]
                  
                  with mp.Pool(processes=(mp.cpu_count() - 1)) as p:
                      p.map_async(process_males, args_m)
                      p.map_async(process_females, args_f)
                  

                  process_malesprocess_females 都是函數.args_m, args_f 是迭代器

                  Both process_males and process_females are fuctions. args_m, args_f are iterators

                  另外,我不需要返回任何東西.代理是需要更新的類實例.

                  Also, I don't need to return anything. Agents are class instances that need updating.

                  推薦答案

                  if __name__ == '__main__': 的想法是避免無限進程產生.

                  The idea of if __name__ == '__main__': is to avoid infinite process spawning.

                  當腌制在你的主腳本中定義的函數時,python 必須弄清楚你的主腳本的哪一部分是函數代碼.它基本上會重新運行你的腳本.如果您創建 Pool 的代碼在同一個腳本中并且不受if main"保護,那么通過嘗試導入該函數,您將嘗試啟動另一個 Pool這將嘗試啟動另一個 Pool....

                  When pickling a function defined in your main script, python has to figure out what part of your main script is the function code. It will basically re run your script. If your code creating the Pool is in the same script and not protected by the "if main", then by trying to import the function, you will try to launch another Pool that will try to launch another Pool....

                  因此,您應該將函數定義與實際的主腳本分開:

                  Thus you should separate the function definitions from the actual main script:

                  from multiprocessing import Pool
                  
                  # define test functions outside main
                  # so it can be imported withou launching
                  # new Pool
                  def test_func():
                      pass
                  
                  if __name__ == '__main__':
                      with Pool(4) as p:
                          r = p.apply_async(test_func)
                          ... do stuff
                          result = r.get()
                  

                  這篇關于如何在導入的模塊中使用 multiprocessing.Pool?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數傳遞給 pool.map() 函數)
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)

                        • <bdo id='XtJPW'></bdo><ul id='XtJPW'></ul>
                            <tbody id='XtJPW'></tbody>
                          <legend id='XtJPW'><style id='XtJPW'><dir id='XtJPW'><q id='XtJPW'></q></dir></style></legend>
                            <tfoot id='XtJPW'></tfoot>

                            <i id='XtJPW'><tr id='XtJPW'><dt id='XtJPW'><q id='XtJPW'><span id='XtJPW'><b id='XtJPW'><form id='XtJPW'><ins id='XtJPW'></ins><ul id='XtJPW'></ul><sub id='XtJPW'></sub></form><legend id='XtJPW'></legend><bdo id='XtJPW'><pre id='XtJPW'><center id='XtJPW'></center></pre></bdo></b><th id='XtJPW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='XtJPW'><tfoot id='XtJPW'></tfoot><dl id='XtJPW'><fieldset id='XtJPW'></fieldset></dl></div>
                          • <small id='XtJPW'></small><noframes id='XtJPW'>

                            主站蜘蛛池模板: 一级女毛片| 国产91丝袜在线18 | 日韩av在线不卡 | 精品丝袜在线 | www成人免费| 日韩欧美一区二区三区四区 | 国产精品福利网 | .国产精品成人自产拍在线观看6 | 亚洲精品免费在线观看 | av激情在线 | 麻豆国产精品777777在线 | 99热国产精品 | 成人在线观看网站 | 九九色综合| 精品日韩在线 | 国产精品1区2区 | 国产精品1区2区 | 免费一级黄色 | 男女羞羞视频在线看 | 久久精品一区二区三区四区 | 日韩在线视频免费观看 | 91国产精品在线 | 久久精品久久久久久 | 中文字幕在线视频网站 | 日韩精品一 | 一区二区中文 | 国产精品视频在线观看 | 久久剧场 | 久久国产亚洲 | 亚洲视频一区二区三区 | 一级毛片视频在线 | 亚洲精品久久久久久国产精华液 | 精品久久电影 | 97国产在线观看 | 精精国产视频 | 人人玩人人添人人澡欧美 | 亚洲精品一区二三区不卡 | 在线一区视频 | 久久精品91久久久久久再现 | 在线观看黄色大片 | 亚洲视频免费 |