From 6aac4e94459dce2821d458dad1d793337ed1070f Mon Sep 17 00:00:00 2001 From: "Allen95Wei(901)" Date: Fri, 24 Dec 2021 12:32:49 +0800 Subject: [PATCH] =?UTF-8?q?`psutil`=E6=A8=A1=E7=B5=84=E5=87=BA=E7=8F=BE?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E6=99=82=EF=BC=8C=E6=9C=83=E5=82=B3=E9=80=81?= =?UTF-8?q?=E9=8C=AF=E8=AA=A4=E8=A9=B3=E7=B4=B0=E8=A8=8A=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detect_pc_status.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/detect_pc_status.py b/detect_pc_status.py index 33b236f..e7ce784 100644 --- a/detect_pc_status.py +++ b/detect_pc_status.py @@ -1,10 +1,10 @@ def pc_status(): - import psutil - - i = 1 - while i > 0: + try: + import psutil msg = "CPU使用率:" + str(psutil.cpu_percent()) + "%" + " / 記憶體使用率:" + str(psutil.virtual_memory().percent) + "%" - return msg + except Exception as e: + msg = "```" + str(e) + "```" + return msg if __name__ == "__main__":