优化代码
This commit is contained in:
parent
751860f41b
commit
b4246948c0
|
|
@ -94,14 +94,14 @@ def start():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def kill_process_by_port(port):
|
def kill_process_by_port(run_port):
|
||||||
# 执行netstat命令获取端口占用信息
|
# 执行netstat命令获取端口占用信息
|
||||||
cmd_netstat = ['netstat', '-ano', '-p', 'tcp']
|
cmd_netstat = ['netstat', '-ano', '-p', 'tcp']
|
||||||
result = subprocess.run(cmd_netstat, capture_output=True, text=True, shell=True)
|
result = subprocess.run(cmd_netstat, capture_output=True, text=True, shell=True)
|
||||||
|
|
||||||
# 在输出中查找指定端口
|
# 在输出中查找指定端口
|
||||||
pid = None
|
pid = None
|
||||||
pattern = fr':{port}\s+.*LISTENING\s+(\d+)'
|
pattern = fr':{run_port}\s+.*LISTENING\s+(\d+)'
|
||||||
match = re.search(pattern, result.stdout)
|
match = re.search(pattern, result.stdout)
|
||||||
if match:
|
if match:
|
||||||
pid = match.group(1)
|
pid = match.group(1)
|
||||||
|
|
@ -110,11 +110,11 @@ def kill_process_by_port(port):
|
||||||
if pid:
|
if pid:
|
||||||
try:
|
try:
|
||||||
subprocess.run(['taskkill', '/F', '/PID', pid], check=True)
|
subprocess.run(['taskkill', '/F', '/PID', pid], check=True)
|
||||||
logger.info(f"已终止占用端口 {port} 的进程 (PID: {pid})")
|
logger.info(f"已终止占用端口 {run_port} 的进程 (PID: {pid})")
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
logger.info(f"终止进程 {pid} 失败 (可能权限不足或进程不存在)")
|
logger.info(f"终止进程 {pid} 失败 (可能权限不足或进程不存在)")
|
||||||
else:
|
else:
|
||||||
logger.info(f"端口 {port} 未被占用")
|
logger.info(f"端口 {run_port} 未被占用")
|
||||||
|
|
||||||
def open_web():
|
def open_web():
|
||||||
webview.settings['ALLOW_DOWNLOADS'] = True
|
webview.settings['ALLOW_DOWNLOADS'] = True
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue