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

    <bdo id='aKHKp'></bdo><ul id='aKHKp'></ul>
  • <legend id='aKHKp'><style id='aKHKp'><dir id='aKHKp'><q id='aKHKp'></q></dir></style></legend>
    1. <tfoot id='aKHKp'></tfoot>

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

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

      1. Python 多處理模塊的 .join() 方法到底在做什么?

        What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)

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

              1. <tfoot id='3q8ki'></tfoot>
                  <bdo id='3q8ki'></bdo><ul id='3q8ki'></ul>

                  <small id='3q8ki'></small><noframes id='3q8ki'>

                • <legend id='3q8ki'><style id='3q8ki'><dir id='3q8ki'><q id='3q8ki'></q></dir></style></legend>
                    <tbody id='3q8ki'></tbody>
                • 本文介紹了Python 多處理模塊的 .join() 方法到底在做什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  了解 Python 多處理(來自 PMOTW 文章) 并且希望對 join() 方法的具體作用進行一些說明.

                  Learning about Python Multiprocessing (from a PMOTW article) and would love some clarification on what exactly the join() method is doing.

                  在 2008 年的舊教程 中指出如果沒有下面代碼中的 p.join() 調(diào)用,子進程將處于空閑狀態(tài)并且不會終止,成為必須手動殺死的僵尸".

                  In an old tutorial from 2008 it states that without the p.join() call in the code below, "the child process will sit idle and not terminate, becoming a zombie you must manually kill".

                  from multiprocessing import Process
                  
                  def say_hello(name='world'):
                      print "Hello, %s" % name
                  
                  p = Process(target=say_hello)
                  p.start()
                  p.join()
                  

                  我添加了 PIDtime.sleep 的打印輸出來測試,據(jù)我所知,進程自行終止:

                  I added a printout of the PID as well as a time.sleep to test and as far as I can tell, the process terminates on its own:

                  from multiprocessing import Process
                  import sys
                  import time
                  
                  def say_hello(name='world'):
                      print "Hello, %s" % name
                      print 'Starting:', p.name, p.pid
                      sys.stdout.flush()
                      print 'Exiting :', p.name, p.pid
                      sys.stdout.flush()
                      time.sleep(20)
                  
                  p = Process(target=say_hello)
                  p.start()
                  # no p.join()
                  

                  20 秒內(nèi):

                  936 ttys000    0:00.05 /Library/Frameworks/Python.framework/Versions/2.7/Reso
                  938 ttys000    0:00.00 /Library/Frameworks/Python.framework/Versions/2.7/Reso
                  947 ttys001    0:00.13 -bash
                  

                  20 秒后:

                  947 ttys001    0:00.13 -bash
                  

                  行為與在文件末尾添加的 p.join() 相同.本周 Python 模塊提供了非常易讀的模塊說明;要等到進程完成其工作并退出,請使用 join() 方法.",但似乎至少 OS X 無論如何都在這樣做.

                  Behavior is the same with p.join() added back at end of the file. Python Module of the Week offers a very readable explanation of the module; "To wait until a process has completed its work and exited, use the join() method.", but it seems like at least OS X was doing that anyway.

                  我也想知道方法的名稱..join() 方法是否在此處連接任何內(nèi)容?它是否將一個過程與它的結(jié)束連接起來?或者它只是與 Python 的原生 .join() 方法共享一個名稱?

                  Am also wondering about the name of the method. Is the .join() method concatenating anything here? Is it concatenating a process with it's end? Or does it just share a name with Python's native .join() method?

                  推薦答案

                  join() 方法,當(dāng)與 threadingmultiprocessing 一起使用時, 與 str.join() 無關(guān) - 它實際上并沒有將任何東西連接在一起.相反,它只是意味著等待這個[線程/進程]完成".使用名稱 join 是因為 multiprocessing 模塊的 API 看起來類似于 threading 模塊的 API,而 threading 模塊使用 join 作為它的 Thread 對象.使用術(shù)語 join 來表示等待線程完成"在許多編程語言中都很常見,因此 Python 也采用了它.

                  The join() method, when used with threading or multiprocessing, is not related to str.join() - it's not actually concatenating anything together. Rather, it just means "wait for this [thread/process] to complete". The name join is used because the multiprocessing module's API is meant to look as similar to the threading module's API, and the threading module uses join for its Thread object. Using the term join to mean "wait for a thread to complete" is common across many programming languages, so Python just adopted it as well.

                  現(xiàn)在,無論是否調(diào)用 join(),您都會看到 20 秒延遲的原因是因為默認(rèn)情況下,當(dāng)主進程準(zhǔn)備退出時,它會隱式調(diào)用 join() 在所有正在運行的 multiprocessing.Process 實例上.這在 multiprocessing 文檔中沒有明確說明,但在 編程指南部分:

                  Now, the reason you see the 20 second delay both with and without the call to join() is because by default, when the main process is ready to exit, it will implicitly call join() on all running multiprocessing.Process instances. This isn't as clearly stated in the multiprocessing docs as it should be, but it is mentioned in the Programming Guidelines section:

                  還請記住,非守護進程將自動加入.

                  Remember also that non-daemonic processes will be automatically be joined.

                  您可以通過在啟動進程之前將 Process 上的 daemon 標(biāo)志設(shè)置為 True 來覆蓋此行為:

                  You can override this behavior by setting the daemon flag on the Process to True prior to starting the process:

                  p = Process(target=say_hello)
                  p.daemon = True
                  p.start()
                  # Both parent and child will exit here, since the main process has completed.
                  

                  如果你這樣做,子進程 將在主進程后立即終止完成:

                  If you do that, the child process will be terminated as soon as the main process completes:

                  守護進程

                  進程的守護進程標(biāo)志,一個布爾值.這必須在之前設(shè)置start() 被調(diào)用.

                  The process’s daemon flag, a Boolean value. This must be set before start() is called.

                  初始值繼承自創(chuàng)建過程.

                  The initial value is inherited from the creating process.

                  當(dāng)一個進程退出時,它會嘗試終止它的所有守護進程子進程.

                  這篇關(guān)于Python 多處理模塊的 .join() 方法到底在做什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數(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屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進程池.當(dāng)其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)
                  Multiprocessing : use tqdm to display a progress bar(多處理:使用 tqdm 顯示進度條)

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

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

                        2. <legend id='EU5us'><style id='EU5us'><dir id='EU5us'><q id='EU5us'></q></dir></style></legend>

                            <tbody id='EU5us'></tbody>
                            主站蜘蛛池模板: 久久久久久久久久久国产 | 国产综合久久 | 久久久久国产精品午夜一区 | 自拍偷拍中文字幕 | 国产精品永久久久久久久www | 日一区二区 | 日韩有码在线播放 | 在线91 | 国产一区二区三区久久久久久久久 | 天堂在线免费视频 | 男人的天堂在线视频 | 91av视频在线观看 | 日韩国产中文字幕 | 天天看夜夜| 婷婷丁香在线视频 | 国产精品久久久久久久久久免费看 | 国产在线一区二区三区 | 人人人人干 | 亚洲成人精品一区 | 一二三四在线视频观看社区 | 狠狠入ady亚洲精品经典电影 | 欧美日韩久久精品 | 国产一区欧美 | 日韩不卡在线 | 久久不卡区 | 国产精品久久久久久久久久久久 | 日本久久久久久 | 黑人性hd| 北条麻妃一区二区三区在线观看 | 国产成人精品综合 | 国产亚洲精品91 | 伊人爽 | 久久99久久| 免费一区二区 | 国产精品视频一二三区 | 国产精品久久久久久久久久久久 | 国产精品国产三级国产aⅴ中文 | 超碰免费在线 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 欧美一级网站 | 欧美视频免费 |