python_多进程

一、多进程

1、多线程,多进程

    多线程:
适用于io密集型任务
多进程
适用于cpu密集型任务

 1 import multiprocessing,time,virtualenv
 2 def down_load():
 3     time.sleep(5)
 4     print('运行完了')
 5 
 6 if __name__ == '__main__':
 7     for i in range(5):
 8         p = multiprocessing.Process(target=down_load)
 9         p.start()
10     while len(multiprocessing.active_children()) !=0:  #等待子进程结束
11         pass
12 
13     print(multiprocessing.current_process())
14     print('end')

 

 
posted @ 2019-11-30 22:21  xmb  阅读(116)  评论(0编辑  收藏  举报