From 45f8c38a75081eece7809a7568b8479293e3685e Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 6 Feb 2024 16:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9quit()=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_functions/tools.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/DrissionPage/_functions/tools.py b/DrissionPage/_functions/tools.py index dfd2340..49b0bca 100644 --- a/DrissionPage/_functions/tools.py +++ b/DrissionPage/_functions/tools.py @@ -188,6 +188,14 @@ def stop_process_on_port(port, pid=None): :param pid: 进程号 :return: None """ + if pid: + try: + for p in Process(pid).children(): + p.terminate() + Process(pid).terminate() + except: + pass + for proc in process_iter(['pid', 'connections']): try: connections = proc.connections() @@ -202,16 +210,6 @@ def stop_process_on_port(port, pid=None): except Exception as e: print(f"{proc.pid} {port}: {e}") - if pid: - for p in Process(pid).children(): - try: - p.terminate() - except: - pass - try: - Process(pid).terminate() - except: - pass def configs_to_here(save_name=None): """把默认ini文件复制到当前目录