我定义了类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