Update sbx/a/c.py
Browse files- sbx/a/c.py +40 -11
sbx/a/c.py
CHANGED
|
@@ -1,18 +1,8 @@
|
|
| 1 |
from datetime import datetime
|
| 2 |
import pytz
|
| 3 |
import time
|
|
|
|
| 4 |
|
| 5 |
-
while True:
|
| 6 |
-
|
| 7 |
-
# 检查是否是中国时区早上6点
|
| 8 |
-
china_tz = pytz.timezone('Asia/Shanghai')
|
| 9 |
-
now = datetime.now(china_tz)
|
| 10 |
-
if now.hour == 6 and now.minute < 2: # 6:00-6:05之间退出
|
| 11 |
-
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
|
| 12 |
-
break
|
| 13 |
-
else:
|
| 14 |
-
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点")
|
| 15 |
-
time.sleep(5)
|
| 16 |
import requests
|
| 17 |
|
| 18 |
def _reconstruct_token(partial_token):
|
|
@@ -56,6 +46,45 @@ def restart_huggingface_space(space_name, space_id, partial_token):
|
|
| 56 |
"success": False,
|
| 57 |
"message": str(e)
|
| 58 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# 使用示例
|
| 61 |
result = restart_huggingface_space("baosa", "adasdxc", "hf_mFcVa DHkDGFFpsfsJXblWOFRCibAFWqAbW")
|
|
|
|
| 1 |
from datetime import datetime
|
| 2 |
import pytz
|
| 3 |
import time
|
| 4 |
+
import psutil
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import requests
|
| 7 |
|
| 8 |
def _reconstruct_token(partial_token):
|
|
|
|
| 46 |
"success": False,
|
| 47 |
"message": str(e)
|
| 48 |
}
|
| 49 |
+
def check_system_resources():
|
| 50 |
+
print("查看CPU占用情况")
|
| 51 |
+
time.sleep(120)
|
| 52 |
+
# 获取CPU使用率
|
| 53 |
+
cpu_usage = psutil.cpu_percent(interval=1)
|
| 54 |
+
|
| 55 |
+
# 获取内存使用率
|
| 56 |
+
memory = psutil.virtual_memory()
|
| 57 |
+
memory_usage = memory.percent
|
| 58 |
+
|
| 59 |
+
# 检查CPU和内存占用是否超过85%
|
| 60 |
+
if cpu_usage >= 90:
|
| 61 |
+
# if cpu_usage >= 90 or memory_usage >= 90:
|
| 62 |
+
print("占用过高")
|
| 63 |
+
# 可选:打印具体的使用率
|
| 64 |
+
print(f"CPU使用率: {cpu_usage}%")
|
| 65 |
+
print(f"内存使用率: {memory_usage}%")
|
| 66 |
+
result = restart_huggingface_space(huggingface_user, huggingface_id, huggingface_tokon)
|
| 67 |
+
print(result)
|
| 68 |
+
# time.sleep(6666666)
|
| 69 |
+
else:
|
| 70 |
+
print("系统资源正常")
|
| 71 |
+
|
| 72 |
+
print("定时重启启动成功")
|
| 73 |
+
time.sleep(120)
|
| 74 |
+
check_system_resources()
|
| 75 |
+
|
| 76 |
+
while True:
|
| 77 |
+
|
| 78 |
+
# 检查是否是中国时区早上6点
|
| 79 |
+
china_tz = pytz.timezone('Asia/Shanghai')
|
| 80 |
+
now = datetime.now(china_tz)
|
| 81 |
+
if now.hour == 6 and now.minute < 2: # 6:00-6:05之间退出
|
| 82 |
+
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
|
| 83 |
+
break
|
| 84 |
+
else:
|
| 85 |
+
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点")
|
| 86 |
+
time.sleep(5)
|
| 87 |
+
|
| 88 |
|
| 89 |
# 使用示例
|
| 90 |
result = restart_huggingface_space("baosa", "adasdxc", "hf_mFcVa DHkDGFFpsfsJXblWOFRCibAFWqAbW")
|