参考:https://www.cnblogs.com/cindy-cindy/p/8031731.html
python进程管理的模块:subprocess,multiprocessing
subprocess:运行外部的程序,而不是运行python内部编写的函数。进程之间通过管道进行交流。
1.开启一个进程
popen1=subprocess.Popen('tail -f events.log’, bufsize=10000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
#popen1是读取events.log的进程,如果希望通过进程的stdin,与其交换数据,在创建Popen对象时,参数stdin必须设置为PIPE; #stdout/stderr同理
#PIPE为管道,如果使用了管道,需要处理管道的输出。
line = popen1.stdout.readline().strip() #清理输出,避免死锁
multiprocessing模块的使用
frome multiprocessing import Queue,Process,Pool
Process类
1.创建子进程
p1 = multiprocessing.Process(target = listen, args = (rdevice,))
p2 = multiprocessing.Process(target = getcpuinfo, args = (rdevice,))
2.启动子进程
&nbs