[英]TypeError: int() argument must be a string or a number, not 'Popen' Python
I have these lines using Popen 我有这些行使用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)
but run into this traceback error 但是碰到这个回溯错误
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'
On this line 在这条线上
numthreads = int(numsibling)/int(numcores)
I'm new to scripting is there anyway to assign these Popen values to a string or int so this works? 我是脚本的新手,无论如何都可以将这些Popen值分配给字符串或整数,所以这可行吗? I don't think doing a simple numcpu== 'anything' works but I could be wrong?
我不认为做一个简单的numcpu =='anything'可以,但是我可能错了? Any help for a beginner?
对初学者有帮助吗? Nothing I can find on here (SO) for similar cases, work for my case unfortunately.
对于类似的案例,我在这里(SO)找不到任何东西,很遗憾,我的案例无法正常工作。 Thanks!
谢谢!
您可以使用proc_name.stdout.readline()
读取标准输出,然后将其转换为int
。
numthreads = int(numsibling.stdout.readline())/int(numcores.stdout.readline())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.