From d5209ea7bca1f2a6bbba394dba9a14f5958f643a Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Sun, 22 Oct 2023 20:47:05 +0800 Subject: [PATCH] get_cpu_usage(interval=1) --- API_Reference/API_Reference.py | 3 +++ Source_Code/PyPI/src/guan/__init__.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/API_Reference/API_Reference.py b/API_Reference/API_Reference.py index ea80987..2fece80 100644 --- a/API_Reference/API_Reference.py +++ b/API_Reference/API_Reference.py @@ -851,6 +851,9 @@ hashed_password = guan.encryption_MD5(password, salt='') # 使用SHA-256进行散列加密 hashed_password = guan.encryption_SHA_256(password, salt='') +# 获取CPU使用率 +cpu_usage = guan.get_cpu_usage(interval=1) + # 获取当前日期字符串 datetime_date = guan.get_date(bar=True) diff --git a/Source_Code/PyPI/src/guan/__init__.py b/Source_Code/PyPI/src/guan/__init__.py index 4111d6e..fed9120 100644 --- a/Source_Code/PyPI/src/guan/__init__.py +++ b/Source_Code/PyPI/src/guan/__init__.py @@ -3694,6 +3694,12 @@ def encryption_SHA_256(password, salt=''): hashed_password = hashlib.sha256(password.encode()).hexdigest() return hashed_password +# 获取CPU使用率 +def get_cpu_usage(interval=1): + import psutil + cpu_usage = psutil.cpu_percent(interval=interval) + return cpu_usage + # 获取当前日期字符串 def get_date(bar=True): import datetime