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

    <legend id='qtorl'><style id='qtorl'><dir id='qtorl'><q id='qtorl'></q></dir></style></legend>
  1. <small id='qtorl'></small><noframes id='qtorl'>

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

      多處理啟動太多 Python VM 實例

      Multiprocessing launching too many instances of Python VM(多處理啟動太多 Python VM 實例)
        <bdo id='8ntAu'></bdo><ul id='8ntAu'></ul>

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

          <small id='8ntAu'></small><noframes id='8ntAu'>

              <legend id='8ntAu'><style id='8ntAu'><dir id='8ntAu'><q id='8ntAu'></q></dir></style></legend><tfoot id='8ntAu'></tfoot>
                  <tbody id='8ntAu'></tbody>
                本文介紹了多處理啟動太多 Python VM 實例的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我正在編寫一些多處理代碼(Python 2.6.4、WinXP)來生成進程以運行后臺任務.在玩一些瑣碎的例子時,我遇到了一個問題,即我的代碼只是不斷產生新的進程,即使我只告訴它產生一個固定的數字.

                I am writing some multiprocessing code (Python 2.6.4, WinXP) that spawns processes to run background tasks. In playing around with some trivial examples, I am running into an issue where my code just continuously spawns new processes, even though I only tell it to spawn a fixed number.

                程序本身運行良好,但如果我查看 Windows 任務管理器,我不斷看到新的python.exe"進程出現.隨著程序的運行(最終使我的機器挨餓),它們只會越來越多地產生.

                The program itself runs fine, but if I look in Windows TaskManager, I keep seeing new 'python.exe' processes appear. They just keep spawning more and more as the program runs (eventually starving my machine).


                例如,
                我希望下面的代碼能夠啟動 2 個 python.exe 進程.第一個是程序本身,第二個是它產生的子進程.知道我做錯了什么嗎?


                For example,
                I would expect the code below to launch 2 python.exe processes. The first being the program itself, and the second being the child process it spawns. Any idea what I am doing wrong?

                import time
                import multiprocessing
                
                
                class Agent(multiprocessing.Process):
                    def __init__(self, i):
                        multiprocessing.Process.__init__(self)
                        self.i = i
                
                    def run(self):
                        while True:
                            print 'hello from %i' % self.i
                            time.sleep(1)
                
                
                agent = Agent(1)
                agent.start()
                

                推薦答案

                您似乎沒有仔細遵循文檔中的指南,特別是 本節 討論安全導入主模塊".

                It looks like you didn't carefully follow the guidelines in the documentation, specifically this section where it talks about "Safe importing of main module".

                您需要使用 if __name__ == '__main__': 塊來保護您的啟動代碼,否則我相信您會得到您所得到的.

                You need to protect your launch code with an if __name__ == '__main__': block or you'll get what you're getting, I believe.

                我認為這歸結為多處理模塊無法像在 Linux 上那樣使用 os.fork(),在 Linux 中,已經運行的進程基本上克隆在內存中.在 Windows(沒有這樣的 fork())上,它必須運行一個新的 Python 解釋器并告訴它導入你的主模塊,然后在完成后執行 start/run 方法.如果您有模塊級別"的代碼,不受名稱檢查的保護,那么在導入過程中它會重新開始整個序列,無窮無盡

                I believe it comes down to the multiprocessing module not being able to use os.fork() as it does on Linux, where an already-running process is basically cloned in memory. On Windows (which has no such fork()) it must run a new Python interpreter and tell it to import your main module and then execute the start/run method once that's done. If you have code at "module level", unprotected by the name check, then during the import it starts the whole sequence over again, ad infinitum

                這篇關于多處理啟動太多 Python VM 實例的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

                  1. <tfoot id='rvOtz'></tfoot>

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

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

                          <bdo id='rvOtz'></bdo><ul id='rvOtz'></ul>
                        • 主站蜘蛛池模板: 长江船运_国内海运_内贸船运_大件海运|运输_船舶运输价格_钢材船运_内河运输_风电甲板船_游艇运输_航运货代电话_上海交航船运 | 杭州代理记账多少钱-注册公司代办-公司注销流程及费用-杭州福道财务管理咨询有限公司 | 冷凝水循环试验箱-冷凝水试验箱-可编程高低温试验箱厂家-上海巨为(www.juweigroup.com) | 青岛球场围网,青岛车间隔离网,青岛机器人围栏,青岛水源地围网,青岛围网,青岛隔离栅-青岛晟腾金属制品有限公司 | 北京办公室装修,办公室设计,写字楼装修-北京金视觉装饰工程公司 北京成考网-北京成人高考网 | 搪玻璃冷凝器_厂家-越宏化工设备 | 不锈钢水箱厂家,不锈钢保温水箱-山东桑特供水设备 | 天坛家具官网| 东莞爱加真空科技有限公司-进口真空镀膜机|真空镀膜设备|Polycold维修厂家 | 桥架-槽式电缆桥架-镀锌桥架-托盘式桥架 - 上海亮族电缆桥架制造有限公司 | 截齿|煤截齿|采煤机截齿|掘进机截齿|旋挖截齿-山东卓力截齿厂家报价 | 专业生产动态配料系统_饲料配料系统_化肥配料系统等配料系统-郑州鑫晟重工机械有限公司 | 【甲方装饰】合肥工装公司-合肥装修设计公司,专业从事安徽办公室、店面、售楼部、餐饮店、厂房装修设计服务 | 深圳离婚律师咨询「在线免费」华荣深圳婚姻律师事务所专办离婚纠纷案件 | 移动机器人产业联盟官网| 汽车整车综合环境舱_军标砂尘_盐雾试验室试验箱-无锡苏南试验设备有限公司 | 耐腐蚀泵,耐腐蚀真空泵,玻璃钢真空泵-淄博华舜耐腐蚀真空泵有限公司 | 科研ELISA试剂盒,酶联免疫检测试剂盒,昆虫_植物ELISA酶免试剂盒-上海仁捷生物科技有限公司 | 煤矿支护网片_矿用勾花菱形网_缝管式_管缝式锚杆-邯郸市永年区志涛工矿配件有限公司 | 圣才学习网-考研考证学习平台,提供万种考研考证电子书、题库、视频课程等考试资料 | 合肥宠物店装修_合肥宠物美容院装修_合肥宠物医院设计装修公司-安徽盛世和居装饰 | 水质监测站_水质在线分析仪_水质自动监测系统_多参数水质在线监测仪_水质传感器-山东万象环境科技有限公司 | 营养师网,营养师考试时间,报名入口—网站首页 | 热缩管切管机-超声波切带机-织带切带机-无纺布切布机-深圳市宸兴业科技有限公司 | 超细|超微气流粉碎机|气流磨|气流分级机|粉体改性机|磨粉机|粉碎设备-山东埃尔派粉体科技 | 数控专用机床,专用机床,自动线,组合机床,动力头,自动化加工生产线,江苏海鑫机床有限公司 | 学考网学历中心| 手术室净化厂家-成都做医院净化工程的公司-四川华锐-15年特殊科室建设经验 | 小型单室真空包装机,食品单室真空包装机-百科 | 窖井盖锯圆机_锯圆机金刚石锯片-无锡茂达金刚石有限公司 | 冷藏车厂家|冷藏车价格|小型冷藏车|散装饲料车厂家|程力专用汽车股份有限公司销售十二分公司 | 水稻烘干机,小麦烘干机,大豆烘干机,玉米烘干机,粮食烘干机_巩义市锦华粮食烘干机械制造有限公司 水环真空泵厂家,2bv真空泵,2be真空泵-淄博真空设备厂 | 电动葫芦|手拉葫芦|环链电动葫芦|微型电动葫芦-北京市凌鹰起重机械有限公司 | 珠海冷却塔降噪维修_冷却塔改造报价_凉水塔风机维修厂家- 广东康明节能空调有限公司 | 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 | 2025世界机器人大会_IC China_半导体展_集成电路博览会_智能制造展览网 | 煤棒机_增碳剂颗粒机_活性炭颗粒机_木炭粉成型机-巩义市老城振华机械厂 | 耐高温电缆厂家-远洋高温电缆 | 广州中央空调回收,二手中央空调回收,旧空调回收,制冷设备回收,冷气机组回收公司-广州益夫制冷设备回收公司 | 并离网逆变器_高频UPS电源定制_户用储能光伏逆变器厂家-深圳市索克新能源 | 切铝机-数控切割机-型材切割机-铝型材切割机-【昆山邓氏精密机械有限公司】 |