python定时器
来源:互联网 发布:sql 存储过程中 事物 编辑:程序博客网 时间:2024/05/21 17:27
只执行一次的定时器
再主函数中
2秒后执行show这个函数并传入参数thime,如果不想传入参数
上面代码中是使用了myshow和myshow2两个定时器,如果想使用一个变量和再一些时间后想要停止定时器
#!/usr/bin/python# -*- coding: UTF-8 -*-import threadingdef main(): myshow = threading.Timer(2,lambda :show("thime")) myshow.start()def show(text): print "hello"+str(text)if __name__ == '__main__': main()
再主函数中
myshow = threading.Timer(2,lambda :show("thime"))
2秒后执行show这个函数并传入参数thime,如果不想传入参数
myshow = threading.Timer(2,show)
再把show方法中的参数改写一下。
上面只是执行一次如果想执行多次,
#!/usr/bin/python# -*- coding: UTF-8 -*-import threadingdef main(): myshow = threading.Timer(2,show) myshow.start()def show(): print "hello time!" myshow2 = threading.Timer(2,show) myshow2.start()if __name__ == '__main__': main()
上面代码中是使用了myshow和myshow2两个定时器,如果想使用一个变量和再一些时间后想要停止定时器
#!/usr/bin/python# -*- coding: UTF-8 -*-import threadingimport timedef main(): global myshow myshow = threading.Timer(2,show) myshow.start() # 5秒后停止定时器 time.sleep(5) myshow.cancel()def show(): print "hello time!" global myshow myshow = threading.Timer(2,show) myshow.start()if __name__ == '__main__': main()主函数再沉睡5秒后,关闭定时器
myshow.cancel()
0 0
- Python定时器
- python 定时器
- python定时器
- Python定时器
- Python 定时器
- python 定时器
- python 定时器
- python定时器
- python定时器
- Python 定时器
- python 定时器
- Python定时器
- Python定时器
- Python定时器
- python 应用crontab 定时器
- Python 定时器 timer
- Python 定时器 timer
- python编程(定时器)
- 检测客户端是PC,微信还是手机
- c#中自带的排序方法
- 关于json解析的几种方法
- 好用的录屏软件activepresenter
- jackson 实现 javabean 与 json、xml 互转
- python定时器
- 用纯css创建三角形
- [Guava源码日报](9)Closeables
- VS2013多字节工程问题
- UGUI缓动血条制作
- 1038: 角谷猜想
- Storm实例
- 克服跨洋网络延迟,使用Docker Hub Mirror加速Docker官方镜像下载
- Tensorflow学习:线性回归问题