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

                問題描述

                限時送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="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>
                        • 主站蜘蛛池模板: 综合一区二区三区 | 日韩一区二区三区精品 | 中文字幕精品一区久久久久 | 久久久久网站 | 精品国产精品国产偷麻豆 | 精品在线免费观看视频 | 色五月激情五月 | 中文字幕在线观看一区 | 免费看黄色小视频 | 成人久久 | 国产精品99久久久久久久久久久久 | 国产精品精品 | 91麻豆精品一区二区三区 | 日本黄色免费大片 | 九九热精品免费 | 久久久精品影院 | 久久久久久久久久久爱 | 午夜精品一区 | 久久久久国产精品一区 | 波多野结衣在线观看一区二区三区 | 一级大黄色片 | 成人在线免费视频 | 91网站在线看 | 手机在线一区二区三区 | 国产剧情久久 | 在线观看中文视频 | 国产精品久久久久久高潮 | 成人小视频在线观看 | 日韩a视频 | 日本不卡一区二区三区 | 亚洲成网 | 四虎永久免费在线 | 国产成人精品一区二 | 国产网站久久 | 国产精品资源在线 | 色眯眯视频在线观看 | 国产精品视频免费观看 | 久久久网 | 亚洲成人精品一区二区 | 欧美日韩在线精品 | 日韩毛片在线视频 |