网站备案好处,不同类型网站比较,亳州网站建设公司,成都哪家做网站最好本文实例讲述了Python mutiprocessing多线程池pool操作。分享给大家供大家参考#xff0c;具体如下#xff1a;python — mutiprocessing 多线程 pool脚本代码#xff1a;root72132server:~/python/multiprocess# lsmultiprocess_pool.py multprocess.pyroot72132server:~/p…本文实例讲述了Python mutiprocessing多线程池pool操作。分享给大家供大家参考具体如下python — mutiprocessing 多线程 pool脚本代码root72132server:~/python/multiprocess# lsmultiprocess_pool.py multprocess.pyroot72132server:~/python/multiprocess# cat multiprocess_pool.py#!/usr/bin/python# --*-- coding:utf-8 --*--import multiprocessingimport sys,os,timeresult []#把运行的进程池放入空的列表def run(msg):#定义正在处理进程编号数的函数功能print threading number:%s %s %(msg,os.getpid())#打印正在处理的进程编号数与对应的系统进程号time.sleep(2)p multiprocessing.Pool(processes 25)#绑定事例同时执行25个线程for i in range(100):result.append(p.apply_async(run,(%s %i,)))#异步传输正在运行的进程数字号码p.close()#关闭正在运行的25个进程#p.join()for res in result:#获取运行结果res.get(timeout5)root72132server:~/python/multiprocess#运行情况1)脚本运行root72132server:~/python/multiprocess# python multiprocess_pool.pythreading number:0 27912threading number:1 27915threading number:2 27913threading number:3 27916threading number:4 27917threading number:5 27918threading number:6 27919threading number:7 27920threading number:8 27922threading number:9 27923threading number:10 27924threading number:11 27925threading number:12 27926threading number:13 27927threading number:14 27928threading number:15 27914threading number:16 27929threading number:17 27921threading number:18 27930threading number:19 27931threading number:20 27932threading number:21 27934threading number:22 27935threading number:23 27936threading number:24 27933threading number:25 27912threading number:26 27915threading number:27 27917threading number:28 27918threading number:29 27916threading number:30 27913threading number:31 27922threading number:32 27919threading number:33 27920threading number:34 27923threading number:35 27924threading number:36 27925threading number:37 27927threading number:38 27921threading number:39 27930threading number:40 27932threading number:41 27934threading number:42 27935threading number:43 27926threading number:44 27931threading number:45 27928threading number:46 27929threading number:47 27914threading number:48 27933threading number:49 27936threading number:50 27912threading number:51 279152)进程查看(25个进程同时运行)root72132server:~/python/multiprocess# ps -ef | grep multiroot 27905 23930 0 22:39 pts/3 00:00:00 grep multiroot72132server:~/python/multiprocess# ps -ef | grep multiroot 27911 20609 1 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27912 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27913 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27914 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27915 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27916 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27917 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27918 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27919 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27920 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27921 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27922 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27923 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27924 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27925 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27926 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27927 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27928 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27929 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27930 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27931 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27932 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27933 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27934 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27935 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27936 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27941 23930 0 22:39 pts/3 00:00:00 grep multiroot72132server:~/python/multiprocess# ps -ef | grep multiroot 27911 20609 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27912 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27913 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27914 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27915 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27916 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27917 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27918 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27919 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27920 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27921 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27922 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27923 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27924 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27925 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27926 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27927 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27928 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27929 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27930 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27931 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27932 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27933 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27934 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27935 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27936 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.pyroot 27943 23930 0 22:39 pts/3 00:00:00 grep multiroot72132server:~/python/multiprocess#希望本文所述对大家Python程序设计有所帮助。