淺顯點理解:進程就是一個程序,裏面的線程就是用來幹活的,,,進程大,線程小windows
1、多線程threading多線程
簡單的單線程和多線程運行:一個參數時,後面要加逗號函數
步驟:for循環,至關於多個線程——t=threading.Thread(target=函數名,args=(參數,))——t.start()——while threading.active_count()!=1:pass線程
添加主線程的打印功能,會發現,會先運行完主線程,纔會去運行子線程blog
要想先運行完子線程再去運行主線程的2個辦法:進程
舉例:多線程下載圖片圖片
2、多進程multiprocessing:windows必定要放在if __name__=='__mian__'下面運行,不然會報錯ip
步驟:for循環,至關於建立多個進程——p=multiprocessing.Process(target=函數名,args=(參數,))——p.start()——while len(multiprocessing.active_children())!=1: passget
3、線程池 threadpoolit
步驟:pool=threadpool.ThreadPool(200)——reqs=threadpool.makeRequests(函數名,數據)——[pool.putRequest(t) for t in reqs]——pool.wait()