您的位置:首页 > 编程语言 > Python开发

Python开启一个线程定时器

2017-08-26 12:59 155 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐