python 多线程计时

import threading,time

class mythread(threading.Thread):

    def __init__(self):
        super(mythread,self).__init__()
        self.__running = threading.Event()
        self.__running.set()

    def run(self):
        i = 0
        while self.__running.isSet():
            print("{0} time {1}".format("\r"*20,i)),
            i +=1
            time.sleep(1)

    def stop(self):
        self.__running.clear()


class A(object):

    def a(self):
        M = mythread()
        M.start()
        time.sleep(10)
        M.stop()

猜你喜欢

转载自www.cnblogs.com/xia-dong/p/12807271.html