zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python学习===实现定时发送,方法一

Python方法学习 实现 发送 定时
2023-09-14 09:12:08 时间
#比如每3秒打印一次helloworld:

from threading import Timer def printHello(): print "Hello World" t = Timer(60, printHello) t.start() if __name__ == "__main__": printHello()

这里的运行环境是:python2.7

threading模块中的Timer能够帮助实现定时任务,而且是非阻塞的。每隔60秒执行一次!

再比如:

比如3秒后打印helloworld:

from threading import Timer

def printHello(): print "hello world" Timer(3, printHello).start()