# 1.1进程
from multiprocessing import Process def fun(index): pass if __name__ == '__main__': for i in range(10): p = Process(target=fun,args=(1,)) p.start()
# 1.2进程池
from concurrent.futures import ProcessPoolExecutor def fun(a,b): print(a,b) if __name__ == "__main__": pool = ProcessPoolExecutor(10) pool.submit(fun,1,2)
# 2.1线程
from threading import Thread def fun(index): pass if __name__ == "__main__": t = Thread(target=fun,args=(1,)) t.start()
# 2.2线程池
from concurrent.futures import ThreadPoolExecutor def fun(a,b): print(a,b) if __name__ == "__main__": tpool = ThreadPoolExecutor(10) tpool.submit(fun,1,2)