Python开启一个线程定时器

时间:2022-05-23 00:45:10
import threading
import time
class aa(threading.Thread):
    def __init__(self,no,interval):
        """Costructor"""
        threading.Thread.__init__(self)
        self.no = noself.interval =interval  self.isstop = False
        def run(self):
            while not self.isstop:
                print 'thread %d' %self.no
                time.sleep(self.interval)
    def stop(self):
        self.isstop = True
    def factory():
        t1=aa(1,2)
        t1.start()
        t1.sleep(20)
        t1.stop()
    if __name__ =="__main__"
        factory()