直接拿来用:进程&进程池&线程&线程池
# 1.1进程
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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进程池
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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线程
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from threading import Thread def fun(index): pass if __name__ == "__main__": t = Thread(target=fun,args=(1,)) t.start()
# 2.2线程池
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from concurrent.futures import ThreadPoolExecutor def fun(a,b): print(a,b) if __name__ == "__main__": tpool = ThreadPoolExecutor(10) tpool.submit(fun,1,2)
-----------------------------------------------------------------------------------------------------------------------------------------