[python]线程继承和参数传递

import threading
import time


class MyThread(threading.Thread):
    def __init__(self, arg):
        # 显式的调用父类的初始化函数。
        #super(MyThread, self).__init__()
        super().__init__()
        self.arg = arg

    # 定义每个线程要运行的函数
    def start(self):
        for i in range(5):
            print("test{}:{}".format(self.arg, i + 1))
            time.sleep(0.1)


if __name__ == "__main__":
    t = MyThread('A')
    t.daemon=True
    t.start()
    while True:
        time.sleep(0.1)

你可能感兴趣的:(Python,python,开发语言)