From b94969a0a1c570ba9903397437835cd869403dbb Mon Sep 17 00:00:00 2001 From: Kailigithub Date: Sun, 31 May 2026 03:04:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=20frontends=20=E4=B8=AD=20stapp.py=20=E5=92=8C=20stapp2.py=20?= =?UTF-8?q?=E7=9A=84=E8=A3=B8=20except=20=E5=AD=90=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 `except: pass` 替换为 `except Exception: pass`,符合 Python 最佳实践, 避免捕获系统退出异常(KeyboardInterrupt、SystemExit),确保程序在重新配置 stdout/stderr 失败时仍能正常退出。 --- frontends/stapp.py | 4 ++-- frontends/stapp2.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/stapp.py b/frontends/stapp.py index 29b8951e5..9e0bdc901 100644 --- a/frontends/stapp.py +++ b/frontends/stapp.py @@ -4,9 +4,9 @@ if sys.stdout is None: sys.stdout = open(os.devnull, "w") if sys.stderr is None: sys.stderr = open(os.devnull, "w") try: sys.stdout.reconfigure(errors='replace') -except: pass +except Exception: pass try: sys.stderr.reconfigure(errors='replace') -except: pass +except Exception: pass script_dir = os.path.dirname(__file__) sys.path.append(os.path.abspath(os.path.join(script_dir, '..'))) sys.path.append(os.path.abspath(script_dir)) diff --git a/frontends/stapp2.py b/frontends/stapp2.py index 1d7968f5d..47df57ae2 100644 --- a/frontends/stapp2.py +++ b/frontends/stapp2.py @@ -3,9 +3,9 @@ if sys.stdout is None: sys.stdout = open(os.devnull, "w") if sys.stderr is None: sys.stderr = open(os.devnull, "w") try: sys.stdout.reconfigure(errors='replace') -except: pass +except Exception: pass try: sys.stderr.reconfigure(errors='replace') -except: pass +except Exception: pass sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import streamlit as st