Use python to view the number of cores of the computer's CPU

    psutil (process and system utilities) is a cross-platform library in Python that is used to view the running process and system information of the computer, such as CPU, memory, disk, network, sensor and other related information. Therefore, using psutil, you can perform The system monitors, analyzes and limits process resources and manages running processes.
    The following introduces the use of the psutil package to output information such as the number of CPUs and memory usage in the current computer.
    1) Install dependent packages

pip install pyinstaller
pip install psutil

    2) Create a new showCPU.py file, the content is as follows;
    //showCPU.py

# -*- coding:utf-8 -*-
# time :2020/11/22 15:30
print('欢迎您,我是电脑小助手')
import psutil as ps
import time
print('本机开机的时间是:{}'.format(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(ps.boot_time()))))
print("-------------------------")
print("CPU部分")
print("-------------------------")
print('本机物理CPU个数:{}个'.format(ps.cpu_count()))
print('本机逻辑CPU个数:{}个'.format(ps.cpu_count(logical=False)))
print("-------------------------")
print('内容部分')
print("-------------------------")
print('本机内存大小为:{}个字节'.format(ps.virtual_memory().total))
print('本机已用内存大小为:{}个字节'.format(ps.virtual_memory().used))
print('本机已用内存大小占比为:{}%'.format(ps.virtual_memory().percent))
input()

    3) Package showCPU.py into showCPU.exe

pyinstaller -F showCPU.py

    4) Run the showCPU.exe, the effect is as follows:

cd dist
showCPU.exe

Figure (1) View the CPU and memory usage in the computer

Guess you like

Origin blog.csdn.net/sanqima/article/details/109955787