久久久久久久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>
                            主站蜘蛛池模板: 一区欧美 | 亚洲欧美一区二区三区在线 | 国产精品久久久久久中文字 | 成人国产精品久久久 | 91精品一区二区三区久久久久久 | 国产精品久久久久久 | 狼人伊人影院 | 欧美极品少妇xxxxⅹ免费视频 | 亚洲日本视频 | 亚洲一区二区三区在线 | 亚洲综合二区 | 成人一区精品 | 欧美一区二区三区在线 | 中文字幕免费视频 | 精品国产乱码久久久久久丨区2区 | 日韩一区二区久久 | 亚洲精品福利在线 | 午夜精品久久久 | av在线免费播放 | 日韩欧美手机在线 | 欧美国产在线一区 | avav在线看| 欧美日韩中文字幕在线 | 日本免费一区二区三区四区 | 日韩国产在线观看 | av网站在线看 | 亚洲一区二区av | 一区二区三区在线 | 国产精品视频网 | 亚洲精品亚洲人成人网 | 欧美一页| 久久一起草 | 日韩午夜激情 | 性一爱一乱一交一视频 | 亚洲va欧美va天堂v国产综合 | 国产亚洲人成a在线v网站 | 国产精品一区二区在线观看 | 国产精品18毛片一区二区 | 日韩欧美在线观看视频 | 一区二区在线不卡 | www.天天操|