From b4246948c0d9ea0a868bc35b2e8d9d20c06dc31e Mon Sep 17 00:00:00 2001 From: chenxudong Date: Thu, 5 Jun 2025 11:58:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/start.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/start.py b/src/start.py index c84cece..b76c50d 100644 --- a/src/start.py +++ b/src/start.py @@ -94,14 +94,14 @@ def start(): sys.exit(1) -def kill_process_by_port(port): +def kill_process_by_port(run_port): # 执行netstat命令获取端口占用信息 cmd_netstat = ['netstat', '-ano', '-p', 'tcp'] result = subprocess.run(cmd_netstat, capture_output=True, text=True, shell=True) # 在输出中查找指定端口 pid = None - pattern = fr':{port}\s+.*LISTENING\s+(\d+)' + pattern = fr':{run_port}\s+.*LISTENING\s+(\d+)' match = re.search(pattern, result.stdout) if match: pid = match.group(1) @@ -110,11 +110,11 @@ def kill_process_by_port(port): if pid: try: subprocess.run(['taskkill', '/F', '/PID', pid], check=True) - logger.info(f"已终止占用端口 {port} 的进程 (PID: {pid})") + logger.info(f"已终止占用端口 {run_port} 的进程 (PID: {pid})") except subprocess.CalledProcessError: logger.info(f"终止进程 {pid} 失败 (可能权限不足或进程不存在)") else: - logger.info(f"端口 {port} 未被占用") + logger.info(f"端口 {run_port} 未被占用") def open_web(): webview.settings['ALLOW_DOWNLOADS'] = True