多进程

 
 1 #并发
 2 import multiprocessing,time
 3 import threading
 4 
 5 def thread_run():
 6     print(threading.get_ident())
 7 def run(name):
 8     print("process:%s"%name)
 9     t=threading.Thread(target=thread_run,)#启线程
10     t.start()
11     time.sleep(2)
12     print("over--%s"%name)
13 
14 if __name__ =='__main__':
15     for i in range(10):
16         p=multiprocessing.Process(target=run,args=("%s"%i,))#启进程
17         p.start()

1.io操作不占用cpu

2.计算占用cpu

python多线程,不适合cpu密集操作型的任务,适合io操作密集型的任务

原文地址:https://www.cnblogs.com/hunterYi/p/9075559.html