Python计时器回调方法

2024-05-16 04:18:03 发布

您现在位置:Python中文网/ 问答频道 /正文

from threading import Timer

class test_timer():
    def __init__(self):
        self.awesum="hh"
        self.timer = Timer(1,self.say_hello,args=["WOW"])
    def say_hello(self,message):
        self.awesum=message
        print 'HIHIHIIHIH'
        print message
        raise Exception("hi")

if __name__ == '__main__':
    print 'Got to main'
    x=test_timer()

当我运行上面的代码时,我的回调方法永远不会被触发。我已经尝试解决这个问题好几个小时了,但还是想不出来>;<

为了测试,计时器。我运行此代码并检查x.awesum是否为“WOW”


Tags: 代码fromtestselfmessagehellomaindef