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

 

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根本就没有启动。

我没有找到相关的资料。

权当做一个注意事项了。

 

 

 

 

你可能感兴趣的:(Python,Linux/Unix)