创建线程
import threading def fn(song, sec): for x in range(sec): print("播放歌曲", song, time.ctime()) # 通过args传参数 t = threading.Thread(target=fn, args=(123, 11)) t.start() t.join()
创建线程池
from concurrent.futures import ThreadPoolExecutor pool = ThreadPoolExecutor(max_workers=2) task1 = pool.submit(函数名1) task2 = pool.submit(函数名2) pool.shutdown()