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

  1. <legend id='lVP7q'><style id='lVP7q'><dir id='lVP7q'><q id='lVP7q'></q></dir></style></legend>

      <tfoot id='lVP7q'></tfoot>

    1. <small id='lVP7q'></small><noframes id='lVP7q'>

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

        <bdo id='lVP7q'></bdo><ul id='lVP7q'></ul>

      Python 多處理如何優雅地退出?

      Python Multiprocessing Exit Elegantly How?(Python 多處理如何優雅地退出?)
        • <bdo id='slXaJ'></bdo><ul id='slXaJ'></ul>
          <tfoot id='slXaJ'></tfoot>

            <tbody id='slXaJ'></tbody>

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

                本文介紹了Python 多處理如何優雅地退出?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..
                import multiprocessing
                import time
                
                class testM(multiprocessing.Process):
                
                    def __init__(self):
                        multiprocessing.Process.__init__(self)
                        self.exit = False
                
                    def run(self):
                        while not self.exit:
                            pass
                        print "You exited!"
                        return
                
                    def shutdown(self):
                        self.exit = True
                        print "SHUTDOWN initiated"
                
                    def dostuff(self):
                        print "haha", self.exit
                
                
                a = testM()
                a.start()
                time.sleep(3)
                a.shutdown()
                time.sleep(3)
                print a.is_alive()
                a.dostuff()
                exit()
                

                我只是想知道為什么上面的代碼并沒有真正打印你退出".我究竟做錯了什么?如果是這樣,有人可以指出正確退出的正確方法嗎?(我不是指 process.terminate 或 kill)

                I am just wondering how come the code above doesn't really print "you exited". What am I doing wrong? if so, may someone point me out the correct way to exit gracefully? (I am not referring to process.terminate or kill)

                推薦答案

                您沒有看到這種情況發生的原因是因為您沒有與子進程通信.您正在嘗試使用局部變量(父進程的本地變量)向子進程發出它應該關閉的信號.

                The reason you are not seeing this happen is because you are not communicating with the subprocess. You are trying to use a local variable (local to the parent process) to signal to the child that it should shutdown.

                查看有關同步原語的信息.您需要設置可以在兩個進程中引用的某種信號.一旦你有了這個,你應該能夠在父進程中輕按開關并等待子進程死亡.

                Take a look at the information on synchonization primatives. You need to setup a signal of some sort that can be referenced in both processes. Once you have this you should be able to flick the switch in the parent process and wait for the child to die.

                試試下面的代碼:

                import multiprocessing
                import time
                
                class MyProcess(multiprocessing.Process):
                
                    def __init__(self, ):
                        multiprocessing.Process.__init__(self)
                        self.exit = multiprocessing.Event()
                
                    def run(self):
                        while not self.exit.is_set():
                            pass
                        print "You exited!"
                
                    def shutdown(self):
                        print "Shutdown initiated"
                        self.exit.set()
                
                
                if __name__ == "__main__":
                    process = MyProcess()
                    process.start()
                    print "Waiting for a while"
                    time.sleep(3)
                    process.shutdown()
                    time.sleep(3)
                    print "Child process state: %d" % process.is_alive()
                

                這篇關于Python 多處理如何優雅地退出?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                  <bdo id='qgj6X'></bdo><ul id='qgj6X'></ul>
                  • <small id='qgj6X'></small><noframes id='qgj6X'>

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

                          主站蜘蛛池模板: 国产一区二区三区 | 精品国产青草久久久久96 | 国产91精品久久久久久久网曝门 | 亚洲福利一区二区 | av手机在线免费观看 | 在线欧美视频 | 亚洲视频中文字幕 | 黄色大片在线免费观看 | 欧美一区二区三区精品免费 | 成人黄色三级毛片 | 欧美日韩在线精品 | 日韩欧美一区二区在线播放 | 欧美日韩精品久久久免费观看 | 男人av在线 | 中文字幕免费视频 | 亚洲美乳中文字幕 | 日韩在线观看视频一区 | 久久午夜国产精品www忘忧草 | 日韩中文字幕一区二区 | 天天久久 | 午夜专区| 国产精产国品一二三产区视频 | 日韩精品视频一区二区三区 | 国产欧美在线播放 | 久久久www | 亚洲成人av | 精品一区二区三区在线观看 | 亚洲精品无 | 中文二区 | 亚洲视频二区 | 草在线| 在线免费观看黄视频 | 丝袜久久| 爱草在线 | 综合一区二区三区 | 丁香一区二区 | 成人在线一区二区 | 亚洲精品电影在线观看 | 中文字幕亚洲一区二区va在线 | 国产高清视频在线观看 | 久久综合激情 |