gevent中的定时器 timer的简单使用
2014-02-09 23:06
2667 查看
(1)timer在gevent的core模块,core模块是对 libev库的包装,源码在:https://github.com/surfly/gevent/blob/master/gevent/core.ppyx
(2)我们可以用类loop(反应器)的timer的方法获取一个timer实例,具体函数签名如下:
参数意义:
after--after秒后,第一次运行注册在此timer的回调函数(通过timer的start方法)。当为0,会马上调用回调函数,然后repeat秒后再调用回调函数。
repeat--反复运行注册的回调函数,间隔为repeat秒。默认值为0.0,即调用一次回调函数。当repeat<为正数,会持续每repeat秒回调,除非我们调用timer的stop方法。
(3)实例代码:
(2)我们可以用类loop(反应器)的timer的方法获取一个timer实例,具体函数签名如下:
def timer(self, double after, double repeat=0.0, ref=True, priority=None): return timer(self, after, repeat, ref, priority)
参数意义:
after--after秒后,第一次运行注册在此timer的回调函数(通过timer的start方法)。当为0,会马上调用回调函数,然后repeat秒后再调用回调函数。
repeat--反复运行注册的回调函数,间隔为repeat秒。默认值为0.0,即调用一次回调函数。当repeat<为正数,会持续每repeat秒回调,除非我们调用timer的stop方法。
(3)实例代码:
import gevent def test(a,b): print a,b loop = gevent.get_hub().loop t =loop.timer(0.0, 5) # timer注册回调函数后马上调用回调函数,然后反复每隔5秒调用回调函数 timer.start(test,1,2) loop.run() #运行反应器loop
相关文章推荐
- 如何使用纯PHP实现定时器任务(Timer)
- 内核定时器的简单使用
- JAVA中定时器Timer的使用
- C# 使用定时任务 之 谈谈定时器(Timer)的使用
- Java Timer 定时器的使用
- Java Timer 定时器的使用 4000
- java定时器的使用(Timer)
- Boost.asio的简单使用(timer,thread,io_service类)
- Golang中使用heap编写一个简单高效的定时器模块
- timer定时器的使用
- spring 对 timer 的支持---实现简单的web中定时器操作
- 使用Java 自身Timer API实现定时器的方法
- 使用 CreateTimerQueueTimer 定时器时需要注意的一个参数
- java中的定时器Timer的使用及实例
- Java Timer 定时器的使用
- Java 中Timer和TimerTask 定时器和定时任务使用的例子
- Boost.asio的简单使用(timer,thread,io_service类)
- java timer 定时器的使用
- Java Timer 定时器的使用
- 关于C#线程中使用定时器timer无效