检查服务是否正在运行
()
| 120 | |
| 121 | |
| 122 | def is_server_running(): |
| 123 | """检查服务是否正在运行""" |
| 124 | pid_port = get_server_pid() |
| 125 | if pid_port is None: |
| 126 | return False, {"status": "Server not running..."} |
| 127 | |
| 128 | _, port = pid_port["PID"], pid_port["PORT"] |
| 129 | health_check_endpoint = f"http://0.0.0.0:{port}/health" |
| 130 | |
| 131 | if os.path.exists(LOG_FILE): |
| 132 | with open(LOG_FILE, "r") as f: |
| 133 | msg = f.readlines() |
| 134 | result = parse_tqdm_progress(msg) |
| 135 | |
| 136 | try: |
| 137 | response = requests.get(health_check_endpoint, timeout=2) |
| 138 | return response.status_code == 200, result |
| 139 | except requests.exceptions.RequestException as e: |
| 140 | print(f"Failed to check server health: {e}") |
| 141 | return False, result |
| 142 | |
| 143 | |
| 144 | def parse_tqdm_progress(log_lines): |
no test coverage detected