fix: 强制设置有效 locale 修复 vnpy_ctp CTP 登录崩溃

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 11:38:19 +08:00
parent f73d436077
commit d368317c1b
8 changed files with 85 additions and 16 deletions
+5 -3
View File
@@ -7,9 +7,9 @@ import threading
import time
from typing import Any, Optional
# vnpy_ctp C++ 在部分 Linux 上缺 locale 会抛 std::runtime_error
os.environ.setdefault("LANG", "C.UTF-8")
os.environ.setdefault("LC_ALL", "C.UTF-8")
from locale_fix import ensure_process_locale
ensure_process_locale()
from ctp_symbol import ths_to_vnpy_symbol, to_vnpy_exchange
@@ -89,6 +89,7 @@ class CtpBridge:
self._init_engine()
def _init_engine(self) -> None:
ensure_process_locale()
try:
from vnpy.event import EventEngine
from vnpy.trader.engine import MainEngine
@@ -163,6 +164,7 @@ class CtpBridge:
self._ee.register(EVENT_LOG, _on_log)
try:
ensure_process_locale()
logger.info(
"CTP 连接 [%s] user=%s td=%s env=%s",
mode,