您的位置:首页 > 其它

Twisted TimerService的使用(以及由此带来的诡异事件)

2009-05-05 15:28 591 查看
TimerService是twisted里提供的一个对loopingcall的service封装。

是在服务运行的期间反复执行某个方法的手段。

文档里没有,其实也很简单。

#! /usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on May 5, 2009
@author: Daniel
'''
from twisted.application import service, internet
from twisted.application.internet import TimerService
from twisted.python import log
import sys
#log.startLogging(sys.stdout)
#log.startLogging(open('./log.txt', 'w'))
application = service.Application('RSSServer')
def test():
#log.msg('looping')
print 'looping'
ts = TimerService(1, test)
ts.setServiceParent(application)


现在twistd -noy 一下,应该看到服务正常循环调用。

换个log方式,以twisted log的方法。

#! /usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on May 5, 2009
@author: Daniel
'''
from twisted.application import service, internet
from twisted.application.internet import TimerService
from twisted.python import log
import sys
log.startLogging(sys.stdout)
#log.startLogging(open('./log.txt', 'w'))

application = service.Application('RSSServer')
def test():
log.msg('looping')
#print 'looping'
ts = TimerService(1, test)
ts.setServiceParent(application)


还能运行嘛?

在我的Mac Osx下没法子运行了。

reactor根本就没有启动。

我没有找到相关的资料。

权当做一个注意事项了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: