import threading
import time
def thread_function(name):
print("Thread %s: starting", name)
time.sleep(2)
print("Thread %s: finishing", name)
if __name__ == "__main__":
threads = []
for i in range(6):
t = threading.Thread(target=thread_function, args=(i,))
t.start()
threads.append(t)
print("Main : wait for the thread to finish")
for t in threads:
t.join()
print("Main : all done")
导入库
threading、创建线程并在那里传递函数就足够了