Python3.x:简单时间调度Timer(间隔时间执行),python3.xtimer,Python3.x:
Python3.x:简单时间调度Timer(间隔时间执行),python3.xtimer,Python3.x:
Python3.x:简单时间调度Timer(间隔时间执行)
代码:
import threadingimport timedef fun_timer(): print(‘hello timer‘) global timer #重复构造定时器 timer = threading.Timer(5.8,fun_timer) timer.start()#定时调度timer = threading.Timer(2,fun_timer)timer.start()# 50秒后停止定时器time.sleep(50)timer.cancel()
说明:
(1).threading.Timer()主要有2个参数:第一个参数为时间,第二个参数为函数名;
(2).必须在定时器执行函数内部重复构造定时器,因为定时器构造后只执行1次,必须循环调用;
(3).定时器间隔单位是秒,可以是浮点数,如5.5,0.02等,例中第一次执行fun_timer是2秒后,后面的都是5.8秒后执行。
(4).使用cancel停止定时器的工作;
Python3.x:简单时间调度Timer(间隔时间执行)
相关内容
- python-gevent模块实现socket大并发,,服务器端:geven
- Python3.6.3 IDLE ClearWindow 清屏扩展,,1、http://b
- python单元测试unitest,,import uni
- python运维实战--LVM创建和在线扩容,,python运维实战
- Python iter() 函数,pythoniter函数,iter() 函数用
- python nose测试框架全面介绍十---用例的跳过,pythonnose
- 用python做一个烟花show,python烟花show, 烟花效果如图
- PAT 1084 外观数列python解法,patpython,外观数列是指具有以
- ReferenceError: weakly-referenced object no longer exists Python k
- Python之code对象与pyc文件(二),,上一节:Python
评论关闭