用twisted为未来安排任务(Scheduling tasks for the future)
2012-05-16 16:18
316 查看
我们想再x秒后执行一个任务,可以使用twisted.internet.interfaces.IReactorTime:
from twisted.internet import reactor
def f(s):
print "this will run 3.5 seconds after it was scheduled: %s" % s
reactor.callLater(3.5, f, "hello, world")
如果想每x秒就重复执行一个任务,可以使用twisted.internet.task.LoopingCall:
from twisted.internet import task
def runEverySecond():
print "a second has passed"
l = task.LoopingCall(runEverySecond)
l.start(1.0) # call every second
# l.stop() will stop the looping calls
如果想要取消一个已经安排的任务:
from twisted.internet import reactor
def f():
print "I'll never run."
callID = reactor.callLater(5, f)
callID.cancel()
from twisted.internet import reactor
def f(s):
print "this will run 3.5 seconds after it was scheduled: %s" % s
reactor.callLater(3.5, f, "hello, world")
如果想每x秒就重复执行一个任务,可以使用twisted.internet.task.LoopingCall:
from twisted.internet import task
def runEverySecond():
print "a second has passed"
l = task.LoopingCall(runEverySecond)
l.start(1.0) # call every second
# l.stop() will stop the looping calls
如果想要取消一个已经安排的任务:
from twisted.internet import reactor
def f():
print "I'll never run."
callID = reactor.callLater(5, f)
callID.cancel()
相关文章推荐
- 用twisted为未来安排任务(Scheduling tasks for the future
- 《未来的五种智力》(Five minds for the future)
- Scheduling Tasks定时任务
- 63 Which three components does the Scheduler use for managing tasks within the Oracle environment? (
- Using a Custom Script Library for Common Tasks(refer to MS The Office InfoPath 2003 SDK)
- C++0x: The future of C++-- C++0x:C++的未来
- Snapdragon 820 Deep Learning SDK Will Promise Better Privacy For The Future
- [原创] 我的生活我安排,我的调度我做主!——介绍一个 日程安排/工作计划/任务调度 的Scheduling组件。(一)
- Spring Boot 与 Kotlin 定时任务(Scheduling Tasks)
- THE PAST, PRESENT & FUTURE OF LOCAL STORAGE FOR WEB APPLICATIONS
- ArcGIS API for Silverlight开发入门(5):任务外包——Tasks
- The Future for SharePoint: On Premises Vs Online
- 实时SLAM的未来及与深度学习的比较The Future of Real-Time SLAM and “Deep Learning vs SLAM”
- spring - Scheduling Tasks 计划任务
- 2010年《斯坦福大学开放课程 :人类健康的未来 - 七个颠覆你思想的演讲》 (Open Stanford Course : The Future of Human Health: 7 Very Short Talks That Will Blow You
- New year ,new scratch line,for the future
- The future for mobile application development
- ArcGIS API for Silverlight开发入门(5):任务外包——Tasks
- [专家讲座] ArcGIS API for Silverlight开发入门(5):任务外包——Tasks(转)
- Spring任务调度Scheduling Tasks