pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="sq208oq" 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="iioys22" 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() 方法到底在做什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送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() 調用,子進程將處于空閑狀態并且不會終止,成為必須手動殺死的僵尸".

                  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 的打印輸出來測試,據我所知,進程自行終止:

                  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 秒內:

                  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() 方法是否在此處連接任何內容?它是否將一個過程與它的結束連接起來?或者它只是與 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() 方法,當與 threadingmultiprocessing 一起使用時, 與 str.join() 無關 - 它實際上并沒有將任何東西連接在一起.相反,它只是意味著等待這個[線程/進程]完成".使用名稱 join 是因為 multiprocessing 模塊的 API 看起來類似于 threading 模塊的 API,而 threading 模塊使用 join 作為它的 Thread 對象.使用術語 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.

                  現在,無論是否調用 join(),您都會看到 20 秒延遲的原因是因為默認情況下,當主進程準備退出時,它會隱式調用 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 標志設置為 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:

                  守護進程

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

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

                  初始值繼承自創建過程.

                  The initial value is inherited from the creating process.

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

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

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

                  相關文檔推薦

                  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)
                  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="gca2eic" 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>
                            主站蜘蛛池模板: 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 成都思迪机电技术研究所-四川成都思迪编码器| 济南电缆桥架|山东桥架-济南航丰实业有限公司 | 福兰德PVC地板|PVC塑胶地板|PVC运动地板|PVC商用地板-中国弹性地板系统专业解决方案领先供应商! 福建成考网-福建成人高考网 | 二手注塑机回收_旧注塑机回收_二手注塑机买卖 - 大鑫二手注塑机 二手光谱仪维修-德国OBLF光谱仪|进口斯派克光谱仪-热电ARL光谱仪-意大利GNR光谱仪-永晖检测 | 针焰试验仪,灼热丝试验仪,漏电起痕试验仪,水平垂直燃烧试验仪 - 苏州亚诺天下仪器有限公司 | 净化车间_洁净厂房_净化公司_净化厂房_无尘室工程_洁净工程装修|改造|施工-深圳净化公司 | 彩超机-黑白B超机-便携兽用B超机-多普勒彩超机价格「大为彩超」厂家 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 郑州宣传片拍摄-TVC广告片拍摄-微电影短视频制作-河南优柿文化传媒有限公司 | 恒温恒湿试验箱_高低温试验箱_恒温恒湿箱-东莞市高天试验设备有限公司 | 电地暖-电采暖-发热膜-石墨烯电热膜品牌加盟-暖季地暖厂家 | pH污水传感器电极,溶解氧电极传感器-上海科蓝仪表科技有限公司 | 浙江华锤电器有限公司_地磅称重设备_防作弊地磅_浙江地磅售后维修_无人值守扫码过磅系统_浙江源头地磅厂家_浙江工厂直营地磅 | 移动厕所租赁|移动卫生间|上海移动厕所租赁-家瑞租赁 | 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 河南凯邦机械制造有限公司 | 聚氨酯复合板保温板厂家_廊坊华宇创新科技有限公司 | 北京宣传片拍摄_产品宣传片拍摄_宣传片制作公司-现像传媒 | 新能源汽车电机定转子合装机 - 电机维修设备 - 睿望达 | 质检报告_CE认证_FCC认证_SRRC认证_PSE认证_第三方检测机构-深圳市环测威检测技术有限公司 | 广州中央空调回收,二手中央空调回收,旧空调回收,制冷设备回收,冷气机组回收公司-广州益夫制冷设备回收公司 | 青岛成人高考_山东成考报名网| 沥青灌缝机_路面灌缝机_道路灌缝机_沥青灌缝机厂家_济宁萨奥机械有限公司 | 塑料瓶罐_食品塑料瓶_保健品塑料瓶_调味品塑料瓶–东莞市富慷塑料制品有限公司 | 金属软管_不锈钢金属软管_巩义市润达管道设备制造有限公司 | 齿式联轴器-弹性联轴器-联轴器厂家-江苏诺兴传动联轴器制造有限公司 | 太阳能发电系统-太阳能逆变器,控制器-河北沐天太阳能科技首页 | 风淋室生产厂家报价_传递窗|送风口|臭氧机|FFU-山东盛之源净化设备 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | 仓储货架_南京货架_钢制托盘_仓储笼_隔离网_环球零件盒_诺力液压车_货架-南京一品仓储设备制造公司 | 跨境物流_美国卡派_中大件运输_尾程派送_海外仓一件代发 - 广州环至美供应链平台 | 灌装封尾机_胶水灌装机_软管灌装封尾机_无锡和博自动化机械制造有限公司 | 联系我们老街华纳娱乐公司官网19989979996(客服) | 哈希PC1R1A,哈希CA9300,哈希SC4500-上海鑫嵩实业有限公司 | 智成电子深圳tdk一级代理-提供TDK电容电感贴片蜂鸣器磁芯lambda电源代理经销,TDK代理商有哪些TDK一级代理商排名查询。-深圳tdk一级代理 | 室内室外厚型|超薄型|非膨胀型钢结构防火涂料_隧道专用防火涂料厂家|电话|价格|批发|施工 | 刘秘书_你身边专业的工作范文写作小秘书 | 南京技嘉环保科技有限公司-杀菌除臭剂|污水|垃圾|厕所|橡胶厂|化工厂|铸造厂除臭剂 | 针焰试验仪,灼热丝试验仪,漏电起痕试验仪,水平垂直燃烧试验仪 - 苏州亚诺天下仪器有限公司 | 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 |