fix(tpc): worker cProfile 默认禁用——环境变量 TPC_WORKER_PROF=1 开启
- 之前 getprofile 互斥检查仍冲突(用户环境仍报 Another profiling tool is already active,viztracer --log_multiprocess 场景) - 彻底修复:cProfile 默认不启用(TPC_WORKER_PROF=1 显式开启才启用),与 viztracer 等外部 profiler 完全解耦;开启时仍有 getprofile 让位 + enable 异常兜底双保险 - 冲突根源:Python 只允许一个 profiling tool 活跃,TPC worker cProfile.enable() 检测到 viztracer 注入的 profiler 即抛错 -> worker 崩溃 -> batch 异常 -> 编译终止
This commit is contained in:
1 parent
c2f07e10cd
commit
ebfaacf7bf
1 file changed
+11
-7
@@ -288,14 +288,18 @@ def _ProfileWorker(_fn):
|
||||
def _wrapper(*args, **kwargs):
|
||||
_prof = None
|
||||
try:
|
||||
# 互斥:viztracer 等外部 profiler 已激活(sys.getprofile() 非 None)时
|
||||
# 跳过 cProfile——Python 只允许一个 profiling tool 同时活跃,
|
||||
# cProfile.enable() 会抛 "Another profiling tool is already active"
|
||||
# → worker 崩溃 → batch 异常 → 编译终止(viztracer --log_multiprocess 场景)。
|
||||
# 此时让 viztracer 独占记录,正常编译(无外部 profiler)仍保留 cProfile。
|
||||
if sys.getprofile() is None:
|
||||
# cProfile 默认不启用(环境变量 TPC_WORKER_PROF=1 开启):
|
||||
# Python 只允许一个 profiling tool 同时活跃,TPC 的 cProfile 与
|
||||
# viztracer --log_multiprocess 冲突(cProfile.enable() 检测到已激活
|
||||
# profiler 抛 "Another profiling tool is already active" → worker 崩溃
|
||||
# → batch 异常 → 编译终止)。外部 profiler 活跃(sys.getprofile()
|
||||
# 非 None)时即使开启也跳过让位;enable() 异常兜底吞掉保编译。
|
||||
if os.environ.get('TPC_WORKER_PROF', '0') == '1' and sys.getprofile() is None:
|
||||
_prof = cProfile.Profile()
|
||||
_prof.enable()
|
||||
try:
|
||||
_prof.enable()
|
||||
except RuntimeError:
|
||||
_prof = None
|
||||
return _fn(*args, **kwargs)
|
||||
finally:
|
||||
if _prof is not None:
|
||||
|
||||
Reference in new issue
Block a user