Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否有方法拒绝计划的计时器事件?_Python_Multithreading - Fatal编程技术网

Python 是否有方法拒绝计划的计时器事件?

Python 是否有方法拒绝计划的计时器事件?,python,multithreading,Python,Multithreading,想想这个。我想拒绝执行计时器事件: import threading def say_hello(): print 'hello' threading.Timer(10, say_hello, ()).start() # now for some reason my plans have changed # is there a way to erase that Timer and deny execution of say_hello? t = threading.Timer

想想这个。我想拒绝执行计时器事件:

import threading


def say_hello():
    print 'hello'

threading.Timer(10, say_hello, ()).start()
# now for some reason my plans have changed
# is there a way to erase that Timer and deny execution of say_hello?
t = threading.Timer(10, say_hello, ())
t.start()  # start timer
t.cancel()  # stop it