Because of the Gil's existence, multithreading in Python is not really multi-threading, and if you want to fully use the resources of multicore CPUs, most of the cases in Python use multiple processes.
fromMultiprocessingImportProcessImport Timedeff (name): Time.sleep (1) Print('Hello', Name,time.ctime ())if __name__=='__main__': P_list=[] forIinchRange (3): P= Process (Target=f, args= ('Alvin',)) P_list.append (P) p.start () forIinchP_list:i.join ()Print('End') fromMultiprocessingImportProcessImport Timeclassmyprocess (Process):#def __init__ (self): #Super (myprocess, self). __init__ () ##self. Name = Name defRun (self): Time.sleep (1) Print('Hello', Self.name,time.ctime ())if __name__=='__main__': P_list=[] forIinchRange (3): P=myprocess () P.daemon=True P.start () p_list.append (p)#For p in p_list: #P.join () Print('End')
Python-multiprocessing Module