擅长:python、mysql、java
<blockquote>
<p>get_cpu_percent(interval=0.1)</p>
<p>Return a float representing the process CPU utilization as a percentage.</p>
<p>When interval is > 0.0 <strong>compares process times to system CPU times</strong> elapsed before and after the interval (blocking).</p>
<p>When interval is 0.0 or None <strong>compares process times to system CPU times</strong> elapsed since last call, returning immediately. In this case is recommended for accuracy that this function be called with at least 0.1 seconds between calls.</p>
</blockquote>
<p>这听起来很像是返回了花在<em>非空闲</em>上的CPU时间(即:<em>每个系统CPU时间</em>的进程CPU时间量),而top显示的是进程相对于<strong>实际时间的CPU时间量。考虑到你的数字,这似乎很现实。在</p>
<p>要获得top将显示的值,只需将每个线程的CPU使用率乘以线程运行的内核的CPU使用率就可以了。<code>psutil.cpu_percent</code>应该有帮助。请注意,在乘以百分比之前,您需要将百分比除以100.0(以获得介于0和1之间的“百分比”)。在</p>