久久久久久久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 有什么區(qū)別?

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

        • <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 有什么區(qū)別?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  multiprocessing 模塊中的ThreadPoolPool 有什么區(qū)別.當(dāng)我嘗試我的代碼時(shí),這是我看到的主要區(qū)別:

                  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]
                  

                  我的問(wèn)題是:

                  • 為什么每次在Pool中都會(huì)運(yùn)行outside __main__()"?

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

                  multiprocessing.pool.ThreadPool 不會(huì)產(chǎn)生新進(jìn)程?它只是創(chuàng)建新線程?

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

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

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

                  我在任何地方都沒(méi)有看到任何關(guān)于 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 相同,唯一的區(qū)別是使用線程而不是進(jìn)程來(lái)運(yùn)行工作者邏輯.

                  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 多次打印是因?yàn)槌貙?spawn 5 個(gè)獨(dú)立進(jìn)程.每個(gè)進(jìn)程都會(huì)初始化自己的 Python 解釋器并加載模塊,從而導(dǎo)致頂層 print 再次執(zhí)行.

                  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.

                  請(qǐng)注意,只有在使用 spawn 進(jìn)程創(chuàng)建方法時(shí)才會(huì)發(fā)生這種情況(僅適用于 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 沒(méi)有記錄,因?yàn)樗膶?shí)現(xiàn)從未完成.它缺乏測(cè)試和文檔.你可以在源代碼中看到它的實(shí)現(xiàn).

                  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.

                  我相信下一個(gè)自然問(wèn)題是:何時(shí)使用基于線程的池以及何時(shí)使用基于進(jìn)程的池?

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

                  經(jīng)驗(yàn)法則是:

                  • IO 綁定作業(yè) ->multiprocessing.pool.ThreadPool
                  • CPU 綁定作業(yè) ->multiprocessing.Pool
                  • 混合工作 ->取決于工作量,由于進(jìn)程隔離帶來(lái)的優(yōu)勢(shì),我通常更喜歡 multiprocessing.Pool

                  在 Python 3 上,您可能需要查看 concurrent.future.Executor 池實(shí)現(xiàn).

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

                  這篇關(guān)于多處理模塊中的 ThreadPool 與 Pool 有什么區(qū)別?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個(gè)參數(shù)傳遞給 pool.map() 函數(shù))
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開(kāi)
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對(duì)象沒(méi)有屬性“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>
                            主站蜘蛛池模板: 久久久久久高潮国产精品视 | 亚洲精品色 | 亚洲精品久久久一区二区三区 | 日日天天 | 综合激情网 | 91中文视频 | 国产精品久久久久一区二区三区 | 久久久久久国产精品 | 久久精品欧美一区二区三区不卡 | 国产99久久久国产精品 | 欧美日韩一区二区电影 | 亚洲高清在线 | 久久成人精品 | 91精品国产91久久久久久最新 | 色射综合 | 亚洲精品免费在线 | 精国产品一区二区三区四季综 | 五月天国产视频 | 成人免费大片黄在线播放 | 欧美日韩一区在线观看 | 久久人体视频 | 久久精品一区 | 久草视频观看 | 日韩av看片 | 中文字幕国产视频 | 日韩福利 | 99国产精品久久久久老师 | 午夜精品久久久久久久99黑人 | 国产a级黄色录像 | 久久久久久久电影 | 国产成人免费视频网站高清观看视频 | 99热精品6| 亚洲不卡一 | 亚洲一区视频在线 | 蜜桃av鲁一鲁一鲁一鲁 | 欧美成人a∨高清免费观看 欧美日韩中 | 一区二区三区四区av | 日本黄色短片 | 美女黄18岁以下禁止观看 | 视频一区二区中文字幕日韩 | 综合一区|