1

再会。

我想知道为什么通过使用subprocess.Popen并询问psutil.Process.memory_info()虚拟内存大小开始新进程我得到超过 21 兆字节?(在通过Popen 简单地打印从主脚本传递的标准输入读取的数据开始的脚本中)

主文件

from subprocess import Popen, PIPE, STDOUT
import sys, psutil, shlex

with Popen(shlex.split('python3 ./test.py'), stdin=PIPE, stdout=PIPE, stderr=STDOUT) as proc:

main_stdin = sys.stdin.read()
print('Writting main STDIN stream:', main_stdin)
proc.stdin.write(bytes(main_stdin, 'UTF-8')) # "redirect" main's stdin to test's stdin

mem_info = psutil.Process(proc.pid).memory_info()
print('RSS:', mem_info.rss/1048576) # bytes to megabytes
print('VMS:', mem_info.vms/1048576)

sub_stdout = proc.communicate()[0].decode('UTF-8')
print('Reading sub STDOUT: ', sub_stdout)

测试.py

from sys import stdin

print(stdin.read())

Ubuntu 14.04,Python 3.4

谢谢!

4

0 回答 0