Twisted 中的每个刻度运行一个函数
我正在使用扭曲框架,我需要跟踪自事件开始以来已经过去了多长时间,并在经过一定时间后执行操作。
在我看来,最好的方法是检查反应堆每次滴答的时间戳。如果这是最好的方法,我该怎么做?如果不是,有什么更好的方法?
I'm using the twisted framework, and I need to keep track of how much time has passed since an event has started, and perform an action when a certain amount has passed.
The best way to do that seems to me to be to check against a time-stamp each tick of the reactor. If it is the best way, how do I do it? If it isn't, what's a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要使用
callLater
。
这是一个完整的、可运行的示例,它执行您所要求的操作,“自事件开始以来经过一定时间(时间)后执行操作”。
(我不认为反应堆里真的有“蜱虫”之类的东西,至少,不是我猜你的意思。)
You want to use
callLater
.Here's a complete, runnable example which does what you are asking, "perform an action when a certain amount (of time) has passed since an event has started".
(I don't think there's really any such thing as a 'tick' in the reactor, at least, not in the sense that I'm guessing you mean.)
我正在寻找的功能似乎在这里描述:
在扭曲协议中定期运行函数
这是我的代码:
The functionality I was looking for seems to be described here:
Running a function periodically in twisted protocol
Here's my code: