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

<tfoot id='PRq0x'></tfoot>

  • <legend id='PRq0x'><style id='PRq0x'><dir id='PRq0x'><q id='PRq0x'></q></dir></style></legend>
  • <small id='PRq0x'></small><noframes id='PRq0x'>

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

          <bdo id='PRq0x'></bdo><ul id='PRq0x'></ul>

        多處理模塊中的 ThreadPool 與 Pool 有什么區別?

        What#39;s the difference between ThreadPool vs Pool in the multiprocessing module?(多處理模塊中的 ThreadPool 與 Pool 有什么區別?)

        • <small id='dr6qa'></small><noframes id='dr6qa'>

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

              <tfoot id='dr6qa'></tfoot>
                <bdo id='dr6qa'></bdo><ul id='dr6qa'></ul>
                  <tbody id='dr6qa'></tbody>
                <legend id='dr6qa'><style id='dr6qa'><dir id='dr6qa'><q id='dr6qa'></q></dir></style></legend>
                  本文介紹了多處理模塊中的 ThreadPool 與 Pool 有什么區別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  multiprocessing 模塊中的ThreadPoolPool 有什么區別.當我嘗試我的代碼時,這是我看到的主要區別:

                  Whats the difference between ThreadPool and Pool in multiprocessing module. When I try my code out, this is the main difference I see:

                  from multiprocessing import Pool
                  import os, time
                  
                  print("hi outside of main()")
                  
                  def hello(x):
                      print("inside hello()")
                      print("Proccess id: ", os.getpid())
                      time.sleep(3)
                      return x*x
                  
                  if __name__ == "__main__":
                      p = Pool(5)
                      pool_output = p.map(hello, range(3))
                  
                      print(pool_output)
                  

                  我看到以下輸出:

                  hi outside of main()
                  hi outside of main()
                  hi outside of main()
                  hi outside of main()
                  hi outside of main()
                  hi outside of main()
                  inside hello()
                  Proccess id:  13268
                  inside hello()
                  Proccess id:  11104
                  inside hello()
                  Proccess id:  13064
                  [0, 1, 4]
                  

                  使用線程池":

                  from multiprocessing.pool import ThreadPool
                  import os, time
                  
                  print("hi outside of main()")
                  
                  def hello(x):
                      print("inside hello()")
                      print("Proccess id: ", os.getpid())
                      time.sleep(3)
                      return x*x
                  
                  if __name__ == "__main__":
                      p = ThreadPool(5)
                      pool_output = p.map(hello, range(3))
                  
                      print(pool_output)
                  

                  我看到以下輸出:

                  hi outside of main()
                  inside hello()
                  inside hello()
                  Proccess id:  15204
                  Proccess id:  15204
                  inside hello()
                  Proccess id:  15204
                  [0, 1, 4]
                  

                  我的問題是:

                  • 為什么每次在Pool中都會運行outside __main__()"?

                  • why is the "outside __main__()" run each time in the Pool?

                  multiprocessing.pool.ThreadPool 不會產生新進程?它只是創建新線程?

                  multiprocessing.pool.ThreadPool doesn't spawn new processes? It just creates new threads?

                  如果是這樣,使用 multiprocessing.pool.ThreadPool 與僅使用 threading 模塊有什么區別?

                  If so whats the difference between using multiprocessing.pool.ThreadPool as opposed to just threading module?

                  我在任何地方都沒有看到任何關于 ThreadPool 的官方文檔,有人可以幫我看看在哪里可以找到它嗎?

                  I don't see any official documentation for ThreadPool anywhere, can someone help me out where I can find it?

                  推薦答案

                  multiprocessing.pool.ThreadPool 的行為與 multiprocessing.Pool 相同,唯一的區別是使用線程而不是進程來運行工作者邏輯.

                  The multiprocessing.pool.ThreadPool behaves the same as the multiprocessing.Pool with the only difference that uses threads instead of processes to run the workers logic.

                  你看到的原因

                  hi outside of main()
                  

                  使用 multiprocessing.Pool 多次打印是因為池將 spawn 5 個獨立進程.每個進程都會初始化自己的 Python 解釋器并加載模塊,從而導致頂層 print 再次執行.

                  being printed multiple times with the multiprocessing.Pool is due to the fact that the pool will spawn 5 independent processes. Each process will initialize its own Python interpreter and load the module resulting in the top level print being executed again.

                  請注意,只有在使用 spawn 進程創建方法時才會發生這種情況(僅適用于 Windows 的方法).如果您使用 fork 之一(Unix),您將看到消息只打印一次,就像線程一樣.

                  Note that this happens only if the spawn process creation method is used (only method available on Windows). If you use the fork one (Unix), you will see the message printed only once as for the threads.

                  multiprocessing.pool.ThreadPool 沒有記錄,因為它的實現從未完成.它缺乏測試和文檔.你可以在源代碼中看到它的實現.

                  The multiprocessing.pool.ThreadPool is not documented as its implementation has never been completed. It lacks tests and documentation. You can see its implementation in the source code.

                  我相信下一個自然問題是:何時使用基于線程的池以及何時使用基于進程的池?

                  I believe the next natural question is: when to use a thread based pool and when to use a process based one?

                  經驗法則是:

                  • IO 綁定作業 ->multiprocessing.pool.ThreadPool
                  • CPU 綁定作業 ->multiprocessing.Pool
                  • 混合工作 ->取決于工作量,由于進程隔離帶來的優勢,我通常更喜歡 multiprocessing.Pool

                  在 Python 3 上,您可能需要查看 concurrent.future.Executor 池實現.

                  On Python 3 you might want to take a look at the concurrent.future.Executor pool implementations.

                  這篇關于多處理模塊中的 ThreadPool 與 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)
                  <i id='NuIwp'><tr id='NuIwp'><dt id='NuIwp'><q id='NuIwp'><span id='NuIwp'><b id='NuIwp'><form id='NuIwp'><ins id='NuIwp'></ins><ul id='NuIwp'></ul><sub id='NuIwp'></sub></form><legend id='NuIwp'></legend><bdo id='NuIwp'><pre id='NuIwp'><center id='NuIwp'></center></pre></bdo></b><th id='NuIwp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NuIwp'><tfoot id='NuIwp'></tfoot><dl id='NuIwp'><fieldset id='NuIwp'></fieldset></dl></div>
                  <legend id='NuIwp'><style id='NuIwp'><dir id='NuIwp'><q id='NuIwp'></q></dir></style></legend>
                      • <bdo id='NuIwp'></bdo><ul id='NuIwp'></ul>
                          <tbody id='NuIwp'></tbody>

                          • <small id='NuIwp'></small><noframes id='NuIwp'>

                            <tfoot id='NuIwp'></tfoot>
                            主站蜘蛛池模板: 欧美日韩国产一区二区三区不卡 | 国产一二区免费视频 | 亚洲午夜电影 | 亚洲国产高清在线 | 欧美日日日日bbbbb视频 | 色橹橹欧美在线观看视频高清 | 视频在线一区二区 | 亚洲精品福利在线 | 国产成人精品一区二区三区四区 | 精品福利在线 | 一级免费视频 | av天天干| 精品一区二区不卡 | 最新中文字幕 | 成人二区| 欧美久久精品一级c片 | 黄色av大片 | 伊人激情综合网 | 中文天堂在线观看 | 免费午夜视频 | 精品9999| 免费福利视频一区二区三区 | 久久精品国产久精国产 | 国产精品一区二区欧美黑人喷潮水 | 99精品在线 | 一级做a爰片久久毛片免费看 | 丁香婷婷久久久综合精品国产 | 欧美精品1区 | 日韩在线不卡 | 亚洲+变态+欧美+另类+精品 | 蜜桃特黄a∨片免费观看 | 久久国产精品一区 | 伊人精品国产 | 久久久青草婷婷精品综合日韩 | 91在线观看网址 | 伊人久久综合 | 色综合一区二区 | 日韩国产专区 | 91精品国产乱码久久久久久久久 | 日本久久网| 91精品久久久久久久久久小网站 |