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

    <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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 實例的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時送ChatGPT賬號..

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

                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 任務(wù)管理器,我不斷看到新的python.exe"進程出現(xiàn).隨著程序的運行(最終使我的機器挨餓),它們只會越來越多地產(chǎn)生.

                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 進程.第一個是程序本身,第二個是它產(chǎn)生的子進程.知道我做錯了什么嗎?


                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()
                

                推薦答案

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

                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.

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

                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

                這篇關(guān)于多處理啟動太多 Python VM 實例的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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 中將多個參數(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)

                  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="qwawimqqmiuu" 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>
                        • 主站蜘蛛池模板: 日本国产欧美 | 国产黄色免费视频 | 中文字幕在线观看一区二区三区 | 欧美激情啪啪 | 亚洲精品成人 | av福利网| 午夜国产一区 | 免费看黄网 | 欧美视频区 | 亚洲国产小视频 | 黄色片小视频 | 日韩一区二区三区视频 | 超碰成人在线观看 | 中文字幕精品在线观看 | 四虎在线免费观看视频 | 黄色在线播放 | 精品www| 免费av网站在线观看 | 欧美久久一区二区 | 中文字幕一区二区三区在线观看 | 成人精品免费视频 | av片在线看 | 五月天婷婷激情 | 天天干夜夜爱 | 午夜色婷婷| 91av精品| 欧美黄色免费网站 | 久久午夜视频 | 国产免费一级片 | 欧美激情中文字幕 | 伊人成人在线视频 | 欧美在线视频免费观看 | 久操福利视频 | 午夜视频在线 | 亚洲欧美久久 | 成人黄色一级片 | 久久中文字幕视频 | av中文网| 日韩三级视频 | txvlog.com| 国产精品美女久久 |