Python 多线程
2.5.1. 创建线程
from threading import Thread
import time
def fun1():
print("fun1 begin")
time.sleep(2)
print("fun1 end")
def fun2():
print("fun2 begin")
time.sleep(6)
print("fun2 end")
threads = []
threads.append(Thread(target=fun1))
threads.append(Thread(target=fun2))
print(threads)
if __name__ == "__main__":
for t in threads:
print(t)
t.start()
print("Done")
2.5.2. threading 高级线程接口
threading — Higher-level threading interface
import threading
class MyThread(threading.Thread):
def __init__(self, name=None):
threading.Thread.__init__(self)
self.name = name
d