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

    <tfoot id='rv465'></tfoot>
      <bdo id='rv465'></bdo><ul id='rv465'></ul>
  1. <legend id='rv465'><style id='rv465'><dir id='rv465'><q id='rv465'></q></dir></style></legend>
  2. <small id='rv465'></small><noframes id='rv465'>

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

      如何將生成器用作具有多處理映射功能的可迭代

      How to use a generator as an iterable with Multiprocessing map function(如何將生成器用作具有多處理映射功能的可迭代對象)
        <tbody id='g4fNL'></tbody>
        <bdo id='g4fNL'></bdo><ul id='g4fNL'></ul>

          • <legend id='g4fNL'><style id='g4fNL'><dir id='g4fNL'><q id='g4fNL'></q></dir></style></legend>
            <tfoot id='g4fNL'></tfoot>

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

              <i id='g4fNL'><tr id='g4fNL'><dt id='g4fNL'><q id='g4fNL'><span id='g4fNL'><b id='g4fNL'><form id='g4fNL'><ins id='g4fNL'></ins><ul id='g4fNL'></ul><sub id='g4fNL'></sub></form><legend id='g4fNL'></legend><bdo id='g4fNL'><pre id='g4fNL'><center id='g4fNL'></center></pre></bdo></b><th id='g4fNL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='g4fNL'><tfoot id='g4fNL'></tfoot><dl id='g4fNL'><fieldset id='g4fNL'></fieldset></dl></div>
                本文介紹了如何將生成器用作具有多處理映射功能的可迭代對象的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                當我使用生成器作為帶有 multiprocessing.Pool.map 函數的可迭代參數時:

                When I use a generator as an iterable argument with multiprocessing.Pool.map function:

                pool.map(func, iterable=(x for x in range(10)))
                

                func 被調用之前,生成器似乎已經完全耗盡.

                It seems that the generator is fully exhausted before func is ever called.

                我想生成每個項目并將其傳遞給每個進程,謝謝

                I want to yield each item and pass it to each process, thanks

                推薦答案

                multiprocessing.map 在處理之前將沒有 __len__ 方法的可迭代對象轉換為列表.這樣做是為了幫助計算塊大小,池使用它來對工作參數進行分組并降低調度作業的往返成本.這不是最優的,尤其是當 chunksize 為 1 時,但由于 map 必須以一種或另一種方式耗盡迭代器,它通常不是一個重大問題.

                multiprocessing.map converts iterables without a __len__ method to a list before processing. This is done to aid the calculation of chunksize, which the pool uses to group worker arguments and reduce the round trip cost of scheduling jobs. This is not optimal, especially when chunksize is 1, but since map must exhaust the iterator one way or the other, its usually not a significant issue.

                相關代碼在pool.py中.注意它對 len 的使用:

                The relevant code is in pool.py. Notice its use of len:

                def _map_async(self, func, iterable, mapper, chunksize=None, callback=None,
                        error_callback=None):
                    '''
                    Helper function to implement map, starmap and their async counterparts.
                    '''
                    if self._state != RUN:
                        raise ValueError("Pool not running")
                    if not hasattr(iterable, '__len__'):
                        iterable = list(iterable)
                
                    if chunksize is None:
                        chunksize, extra = divmod(len(iterable), len(self._pool) * 4)
                        if extra:
                            chunksize += 1
                    if len(iterable) == 0:
                        chunksize = 0
                

                這篇關于如何將生成器用作具有多處理映射功能的可迭代對象的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

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

                      • <bdo id='9HlOQ'></bdo><ul id='9HlOQ'></ul>

                        <small id='9HlOQ'></small><noframes id='9HlOQ'>

                          主站蜘蛛池模板: 国产精品视频在线免费观看 | 91色视频在线观看 | 国产黄色大片在线免费观看 | 五月激情婷婷网 | 精品国产一区二区三区久久久四川 | 午夜av电影院 | 国产精品2 | 日韩视频中文字幕 | 在线观看av免费 | 99国产视频 | 中国黄色在线视频 | 黑人精品欧美一区二区蜜桃 | 午夜精品久久久 | 天天色天天射天天干 | 特级做a爱片免费69 精品国产鲁一鲁一区二区张丽 | 国产精品久久久久aaaa九色 | 中日字幕大片在线播放 | 亚洲一区国产精品 | 羞羞网站在线观看 | 日韩毛片| 视频一区二区在线观看 | 亚洲精品欧美一区二区三区 | 尤物视频在线免费观看 | 午夜三区| 午夜av在线| 成人在线视频免费观看 | 国产婷婷色一区二区三区 | 日本一区二区三区四区 | 综合五月婷 | 国产精品免费一区二区三区 | 免费高清av | 久久久亚洲 | 香蕉视频1024 | 亚洲欧美一区二区三区国产精品 | 91精品国产乱码久久蜜臀 | 中文字幕中文字幕 | 国产精品视频导航 | 国产精品免费视频一区 | 蜜桃视频一区二区三区 | 欧美一区二区久久 | 麻豆天堂 |