执行结果:
>>>
('Sun Nov 22 12:51:50 2009', 'aliving...')
('Sun Nov 22 12:51:51 2009', 'aliving...')
('Sun Nov 22 12:51:52 2009', 'aliving...')
('Sun Nov 22 12:51:53 2009', 'aliving...')
('Sun Nov 22 12:51:55 2009', 'aliving...')
('Sun Nov 22 12:51:56 2009', 'aliving...')
('Sun Nov 22 12:51:57 2009', 'aliving...')
('Sun Nov 22 12:51:58 2009', 'aliving...')
('Sun Nov 22 12:51:59 2009', 'aliving...')
dead...
>>>作者: nietsche 时间: 2009-11-22 14:16
不要把self.timer定义在keepAlive函数中。
from python help:
cancel( )
Stop the timer, and cancel the execution of the timer's action. This will only work if the timer is still in its waiting stage.作者: markangelma 时间: 2009-11-22 14:31 标题: 回复 #4 nietsche 的帖子 不在函数体内定义的话,有什么办法能够得到返回值,用来调用cancel呢?作者: asxxi1 时间: 2011-09-06 16:23
from threading import Timer
from time import ctime, sleep