TypeError: int() argument must be a string or a number, not 'Popen' Python

TypeError: int() argument must be a string or a number, not 'Popen' Python

我有这些行使用 Popen

numcpu = sub.Popen("($(cat /proc/cpuinfo | grep 'physical id' | awk '{print $NF}' | sort | uniq | wc -l))", shell=True, stdout=sub.PIPE, stderr=sub.PIPE)
numcores = sub.Popen("($(cat /proc/cpuinfo | grep 'cpu cores' | awk '{print $NF}' | sort | uniq | wc -l))", shell=True, stdout=sub.PIPE, stderr=sub.PIPE)  
numsibling = sub.Popen("($(cat /proc/cpuinfo | grep 'siblings' | awk '{print $NF}' | sort | uniq | wc -l))", shell=True, stdout=sub.PIPE, stderr=sub.PIPE)

但 运行 进入此回溯错误

Traceback (most recent call last):
File "./cputool", line 53, in <module>
CpuTool()
File "./cputool", line 45, in CpuTool
numthreads = int(numsibling)/int(numcores)
TypeError: int() argument must be a string or a number, not 'Popen'

这条线

numthreads = int(numsibling)/int(numcores)

我是脚本新手,是否可以将这些 Popen 值分配给字符串或 int,这样可行吗?我认为做一个简单的 numcpu== 'anything' 行不通,但我可能是错的?对初学者有什么帮助吗?对于类似的案例,我在这里 (SO) 找不到任何东西,不幸的是我的案例。谢谢!

您可以使用 proc_name.stdout.readline() 读取标准输出,然后将其转换为 int

numthreads = int(numsibling.stdout.readline())/int(numcores.stdout.readline())