fix: 控制台强制 UTF-8,避免 emoji 打印异常拖垮采集事务
Windows 中文控制台默认 cp936(GBK),而 app.py / services.core / crawler_106 / crawler_82 大量使用 emoji 打印日志。print 一旦抛 UnicodeEncodeError,异常会 落进采集任务的 try 块,导致整个事务被 rollback 并报“数据写入失败”,表现就是 定时采集长期静默不落库。 实测:在 GBK 管道下 create_app() 直接崩在 app.py 的 emoji print 上。 - app.py 顶部(所有业务 import 之前)强制 stdout/stderr 为 UTF-8。 - 比常见写法多两层守卫:encoding 可能为 None(.lower() 会 AttributeError), PyInstaller --noconsole 或重定向时可能没有 buffer —— 这两个恰好是我们要防的 场景。替换前先 flush,否则旧缓冲区里未写出的内容会随旧对象一起丢。 - 保留原始流引用,防止被 GC 回收时连带关闭底层 buffer。 - auto_monitor_job 瘦身:入库细节全部交给 ingest_device_data。 同时补入 device_monitor.spec(此前未纳入版本管理)与一次性清洗脚本 fix_fake_time.py。
This commit is contained in:
44
2_1banben/device_monitor.spec
Normal file
44
2_1banben/device_monitor.spec
Normal file
@ -0,0 +1,44 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
|
||||
a = Analysis(
|
||||
['app.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[('web_dist', 'web_dist')],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
pyz = PYZ(a.pure)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
[],
|
||||
exclude_binaries=True,
|
||||
name='device_monitor',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
console=True,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
coll = COLLECT(
|
||||
exe,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
name='device_monitor',
|
||||
)
|
||||
Reference in New Issue
Block a user