Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5009172
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类: Python/Ruby

2012-04-06 10:14:18

twisted 的中有一个定时执行类,很象AS3 中的 timer类

LoopingCall 有个start方法,

start方法
第一个参数是函数执行间隔;
第二参数是否现在马上执行;

注意:被调的函数需要有一个self的传参;

下面是在我newjhService对LoopingCall的应用范例:

  1. class newjhService(object):

  2. def __init__(self, pool):
  3. self.conn_pool = pool
  4. LoopingCall(self._keepAlive).start(36000, False)

  5. def _keepAlive(self):
  6. print 'Running Keep Alive...'
  7. self.conn_pool.runOperation('SELECT 1')



  8. def checkUser(self, username, password):
  9. """
  10. Using authentication
  11. """
  12. print 'username : %s passwrd : %s' % (username, password)
  13. def cb(rs):
  14. print rs
  15. if rs == () :
  16. return False
  17. #ret = [ObjectProxy(build_user(row)) for row in rs]
  18. #print ret
  19. #return ArrayCollection(ret)
  20. #if ret == []:
  21. #return False
  22. return True


  23. def eb(failure):
  24. # TODO nick: logging
  25. return ArrayCollection()

  26. d = self.conn_pool.runQuery("SELECT * FROM user where " + \
  27. "UserName= '" +username + "' and Password = '" + \
  28. password +"'" ).addErrback(eb).addCallback(cb)

  29. return d


 

阅读(2043) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~