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

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

        • <bdo id='uefoj'></bdo><ul id='uefoj'></ul>

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

      1. 使用具有最大同時進程數的 multiprocessing.Process

        Using multiprocessing.Process with a maximum number of simultaneous processes(使用具有最大同時進程數的 multiprocessing.Process)
        <i id='JeUZY'><tr id='JeUZY'><dt id='JeUZY'><q id='JeUZY'><span id='JeUZY'><b id='JeUZY'><form id='JeUZY'><ins id='JeUZY'></ins><ul id='JeUZY'></ul><sub id='JeUZY'></sub></form><legend id='JeUZY'></legend><bdo id='JeUZY'><pre id='JeUZY'><center id='JeUZY'></center></pre></bdo></b><th id='JeUZY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JeUZY'><tfoot id='JeUZY'></tfoot><dl id='JeUZY'><fieldset id='JeUZY'></fieldset></dl></div>

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

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

                  <tbody id='JeUZY'></tbody>

                <legend id='JeUZY'><style id='JeUZY'><dir id='JeUZY'><q id='JeUZY'></q></dir></style></legend>
                  本文介紹了使用具有最大同時進程數的 multiprocessing.Process的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有 Python 代碼:

                  from multiprocessing import Process
                  
                  def f(name):
                      print 'hello', name
                  
                  if __name__ == '__main__':
                      for i in range(0, MAX_PROCESSES):
                          p = Process(target=f, args=(i,))
                          p.start()
                  

                  運行良好.但是,MAX_PROCESSES 是可變的,可以是 1512 之間的任何值.由于我只在具有 8 內核的機器上運行此代碼,因此我需要確定是否可以限制允許同時運行的進程數.我查看了 multiprocessing.Queue,但它看起來不像我需要的 - 或者我可能錯誤地解釋了文檔.

                  which runs well. However, MAX_PROCESSES is variable and can be any value between 1 and 512. Since I'm only running this code on a machine with 8 cores, I need to find out if it is possible to limit the number of processes allowed to run at the same time. I've looked into multiprocessing.Queue, but it doesn't look like what I need - or perhaps I'm interpreting the docs incorrectly.

                  有沒有辦法限制同時運行的 multiprocessing.Process 的數量?

                  Is there a way to limit the number of simultaneous multiprocessing.Processs running?

                  推薦答案

                  使用 multiprocessing.Pool 可能是最明智的,它根據可用的最大內核數生成工作進程池您的系統,然后基本上在內核可用時提供任務.

                  It might be most sensible to use multiprocessing.Pool which produces a pool of worker processes based on the max number of cores available on your system, and then basically feeds tasks in as the cores become available.

                  標準文檔中的示例 (http://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers)顯示也可以手動設置核心數:

                  The example from the standard docs (http://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers) shows that you can also manually set the number of cores:

                  from multiprocessing import Pool
                  
                  def f(x):
                      return x*x
                  
                  if __name__ == '__main__':
                      pool = Pool(processes=4)              # start 4 worker processes
                      result = pool.apply_async(f, [10])    # evaluate "f(10)" asynchronously
                      print result.get(timeout=1)           # prints "100" unless your computer is *very* slow
                      print pool.map(f, range(10))          # prints "[0, 1, 4,..., 81]"
                  

                  如果您的代碼中需要,知道有 multiprocessing.cpu_count() 方法來計算給定系統上的內核數量也很方便.

                  And it's also handy to know that there is the multiprocessing.cpu_count() method to count the number of cores on a given system, if needed in your code.

                  這是一些似乎適用于您的特定情況的代碼草案:

                  Here's some draft code that seems to work for your specific case:

                  import multiprocessing
                  
                  def f(name):
                      print 'hello', name
                  
                  if __name__ == '__main__':
                      pool = multiprocessing.Pool() #use all available cores, otherwise specify the number you want as an argument
                      for i in xrange(0, 512):
                          pool.apply_async(f, args=(i,))
                      pool.close()
                      pool.join()
                  

                  這篇關于使用具有最大同時進程數的 multiprocessing.Process的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

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

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

                    • <bdo id='NZdlA'></bdo><ul id='NZdlA'></ul>

                        <tbody id='NZdlA'></tbody>
                      • <legend id='NZdlA'><style id='NZdlA'><dir id='NZdlA'><q id='NZdlA'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 国产日韩欧美精品 | 免费一区二区三区 | 欧美一区免费 | 日韩视频在线免费观看 | 爱爱视频在线观看 | 国产目拍亚洲精品99久久精品 | 天堂中文av | 久久久av一区 | 在线免费观看日本 | 久久精品一 | 国产一区91精品张津瑜 | 日本a∨精品中文字幕在线 亚洲91视频 | 91资源在线播放 | 欧美久久久久久久 | 成年人在线视频 | 午夜精品在线 | 国产a区 | 国产精品久久久久一区二区三区 | 国产精品久久久久久久久污网站 | 午夜在线小视频 | 欧美日韩一二三区 | 亚洲高清视频一区 | 亚洲一区二区久久 | 亚洲天堂一区二区 | 成人在线观看免费爱爱 | 久久亚洲一区二区三 | 一区二区福利视频 | 国外激情av | 欧美偷偷操 | 99热在这里只有精品 | 一二三区av | 日韩午夜影院 | 国产精品欧美一区二区 | 国产午夜精品视频 | 国产视频在线观看一区二区三区 | 亚洲综合三区 | 午夜精品久久久久久久星辰影院 | 97操操 | 久亚州在线播放 | 精品国产青草久久久久96 | 欧美色成人 |