suyuan1573

有时候需要循环执行某个任务,最简单的就是用thread.Timer.

谷歌了一下,发现大家竟然用sleep 来实现循环,也不知道谁想的这个方法,竟然很少有人想到join一下,很奇怪。

# -*- coding: utf-8 -*-
\'\'\'
Created on 2016年4月25日

@author: 55Haitao
\'\'\'

import threading

class Person(object):
    def __init__(self):
        print "init person"
        
    def speak(self):
        print "speak"
        



if __name__ == "__main__":
    p = Person()
    while True:
        timer = threading.Timer(5, Person.speak, (p,))
        print "start"
        timer.start()
        timer.join()
        print "after join"
    
    
    
    
    
    
        
        

  

分类:

技术点:

相关文章:

  • 2022-01-03
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2021-07-22
  • 2022-12-23
猜你喜欢
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案