我定義了類A的方法,它有一個像這樣的方法。在Python中殺死線程
def func(self):
while True:
threading.Timer(0,self.func2, ["0"]).start()
time.sleep(nseconds)
threading.Timer(0,self.func2, ["1"]).start()
time.sleep(nseconds)
如果我在另一個腳本定義這個類的一個實例並運行該實例的func
方法,我怎麼可以打破while循環,正確停止這些線程?我是否需要A類中的ctrl-c信號處理程序,如果是,如何?注意:我也在呼叫os.system
函數的func2
函數的一個系統調用。問題是當我運行主腳本文件並嘗試停止運行這些線程時,它們不停止。
看這裏例如在線程通信http://eli.thegreenplace.net/2011/12/27/python-threads-communication-and-stopping/ – alko