import threading,time
#直接函数方式
# def run1(n):
# print(n)
# time.sleep(2)
# t1 = threading.Thread(target=run1,args=("t1",))
# t1.start()
# t2 = threading.Thread(target=run1,args=("t2",))
# t2.start()
#类方式
class MyThread(threading.Thread):
def __init__(self,n):
super(MyThread,self).__init__()
self.n = n
def run(self): #这里函数名必须是叫run
print("run in thread...",self.n)
time.sleep(2)
t1 = MyThread("t1")
t2 = MyThread("t2")
t1.start()
t2.start()
原文:https://www.cnblogs.com/alex-hrg/p/9013224.html