我正在尝试使用 threading.Timer,我想知道这个计时器是否在另一个线程中启动?所以我需要保护这个定时器访问的变量?
最佳答案
您可以在 threading.py 中看到归档 threading.Timer()
返回一个新的 Thread
实例。或者你可以运行一个例子:
import threading
def ontimer():
print threading.current_thread()
def main():
threading.Timer(2, ontimer).start()
print threading.current_thread()
if __name__=="__main__":
main()
您需要保护 Timer
的回调访问的变量。
关于 python threading.Timer : do i need to protect the variable accessed inside the callback?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4417058/