第一种:
__author__ = 'LL_YING' import threading # 通过继承Thread创建类 class newThread(threading.Thread): def __init__(self, num): threading.Thread.__init__(self) self.num = num def run(self): print("I am", self.num) t1 = newThread(1) t1.start()第二种:
__author__ = 'LL_YING' import threading # 使用threading.Thread直接在线程中运行函数 def run(x, y): for i in range(x, y): print(i) t1 = threading.Thread(target=run, args=(15, 20)) # 直接使用Thread附加函数,args为参数 t1.start()