From 9a3a6c782a0f349f96f72689431d9a5a56eb9951 Mon Sep 17 00:00:00 2001 From: xxm Date: Mon, 24 Aug 2026 12:10:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20install=5Fstdio=5Fhook=E5=B9=82=E7=AD=89?= =?UTF-8?q?=E5=8C=96=E2=80=94=E2=80=94=E5=BA=93=E6=96=87=E4=BB=B6(market?= =?UTF-8?q?=5Fregime=E7=AD=89)=E6=A8=A1=E5=9D=97=E7=BA=A7=5Fmsh()=E8=A2=AB?= =?UTF-8?q?import=E6=97=B6=E4=B8=8D=E5=86=8D=E9=87=8D=E5=A4=8D=E5=8C=85?= =?UTF-8?q?=E8=A3=85stdout(=E5=8F=8C=E5=86=99=E6=A0=B9=E5=9B=A0:per=5Fstoc?= =?UTF-8?q?k=5Freassess=E2=86=92strategy=5Flifecycle=E2=86=92market=5Fregi?= =?UTF-8?q?me=E9=93=BE,N=E5=B1=82hook=3DN=E4=B8=AAbuffer=E5=90=84flush?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=3Dbroadcast=E6=95=B4=E5=9D=97=E9=87=8D?= =?UTF-8?q?=E5=A4=8D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/messenger.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deploy/profile-scripts/messenger.py b/deploy/profile-scripts/messenger.py index fff7f736..09472c7d 100644 --- a/deploy/profile-scripts/messenger.py +++ b/deploy/profile-scripts/messenger.py @@ -211,7 +211,12 @@ def _job_title(script): def install_stdio_hook(script_name=None): - """在脚本入口调用:重定向 stdout 到 messenger 通道控制""" + """在脚本入口调用:重定向 stdout 到 messenger 通道控制。 + 2026-08-24 幂等化:已 hook 则直接复用不重复包装——库文件(如 market_regime)被 import + 时其模块级 _msh() 会变成 no-op,否则 stdout 被包 N 层、N 个 buffer 各 flush 一次, + broadcast 整块重复(双写根因,per_stock_reassess→strategy_lifecycle→market_regime 链实锤)。""" + if isinstance(sys.stdout, _MessengerStdout): + return sys.stdout.channel # 已 hook:幂等返回,不再包装 if script_name is None: script_name = os.path.basename(sys.argv[0]) if sys.argv else "mofin" sys.stdout = _MessengerStdout(sys.stdout, script_name)