|
@@ -12,6 +12,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
from flask_caching import Cache
|
|
|
from scriptBase.minio_manage import *
|
|
|
import subprocess
|
|
|
+from typing import Optional, Any
|
|
|
|
|
|
|
|
|
# 全局线程池,限制最大线程数为1
|
|
@@ -36,7 +37,7 @@ class GlobalState:
|
|
|
g_isRestart = True
|
|
|
last_change_time = time.time()
|
|
|
g_firstRunBear = True
|
|
|
- frp_process = None
|
|
|
+ frp_process: Optional[subprocess.Popen[Any]] = None
|
|
|
|
|
|
def startup_frpc():
|
|
|
GlobalState.frp_process = subprocess.Popen(["tool/frpc.exe", "-c", "tool/frpc-desktop.toml"])
|
|
@@ -44,9 +45,16 @@ def startup_frpc():
|
|
|
def terminate_frpc():
|
|
|
if GlobalState.frp_process is not None:
|
|
|
proc = GlobalState.frp_process
|
|
|
- proc.terminate() # 优雅终止
|
|
|
- if proc.poll() is None: # 检查是否仍在运行
|
|
|
- proc.kill() # 强制终止
|
|
|
+ proc.terminate() # 发送 SIGTERM 信号,尝试优雅终止
|
|
|
+
|
|
|
+ try:
|
|
|
+ proc.wait(timeout=10) # 等待最多10秒
|
|
|
+ print(f"进程已结束,返回值: {proc.returncode}")
|
|
|
+ except subprocess.TimeoutExpired:
|
|
|
+ print("等待超时,进程仍未结束,尝试强制杀死...")
|
|
|
+ proc.kill() # 强制杀死进程
|
|
|
+ proc.wait() # 等待杀死操作完成
|
|
|
+ print("进程已被强制杀死")
|
|
|
|
|
|
@app.after_request
|
|
|
def add_no_cache_header(response):
|
|
@@ -187,6 +195,7 @@ def handle_reset_script():
|
|
|
print(f"重置参数: {[python, script, *new_args, '']}")
|
|
|
|
|
|
terminate_frpc()
|
|
|
+ myTimeSleep_big()
|
|
|
|
|
|
try:
|
|
|
os.execv(python, [python, script, *new_args, ''])
|
|
@@ -445,7 +454,7 @@ def add_auto_task(isMaxCollect, isJina, isSimple = False, isAddStrengh = False,
|
|
|
set_nextTaskTime(nextTaskTime)
|
|
|
myTimeSleep(nextTaskTime, send_status)
|
|
|
if GlobalState.g_isRestart:
|
|
|
- handle_restart_game()
|
|
|
+ http_restart_game()
|
|
|
else:
|
|
|
nextTaskTime = random.randint(400, 450)
|
|
|
set_nextTaskTime(nextTaskTime)
|