代码
import threading
def run_thread1():
while True:
print(“1”)
def run_thread2():
while True:
print(“2”)
t1 = threading.Thread(target=run_thread1)
t2 = threading.Thread(target=run_thread2)
t1.start()
t2.start()
t1.join()
t2.join()
叙述
继承Thread类,并重写它的run()方法,但是会出现只运行前一个线程代码。
输出结果
1
1
2
2
1
1
1