久久久久久久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>

                          主站蜘蛛池模板: 亚洲免费在线观看视频 | 亚洲欧美日韩一区二区 | 久久久91| 国产日韩欧美一区二区 | 日韩欧美中文 | 一区二区三区四区在线播放 | wwwxx在线观看 | 日本免费黄色 | 毛片电影 | 黄色一级大片在线免费看产 | 亚洲视频一区在线 | 色一级| 中文字幕一区二区在线观看 | 亚洲一区 中文字幕 | 欧美国产精品一区二区三区 | 色综合av | 久久久久久久久中文字幕 | 5060网一级毛片| 日本天堂视频在线观看 | 午夜精品视频在线观看 | 国产成人精品免费视频大全最热 | 日日夜夜精品视频 | 少妇精品久久久久久久久久 | 国产高清精品在线 | 精品一区二区三区免费毛片 | 中文二区 | a级毛片免费高清视频 | 成人黄色电影在线播放 | 韩日在线观看视频 | 国产精品成人一区二区 | 日韩一区二区三区在线观看 | 国产一区二区在线播放视频 | 亚洲欧美一区二区三区视频 | 国产成人免费一区二区60岁 | 激情久久网 | 一a一片一级一片啪啪 | 91麻豆精品国产91久久久久久 | 亚洲色图综合 | av在线免费观看网址 | 国产福利网站 | 久久精品综合 |