Prhub

#25710 Remove the dead hasattr fallback around the test-only crash counter

原始 PR 作者 fzyzcjy 合并时间 2026-05-19 09:17 文件变更 1 提交数 1 评论 1 代码增减 +0 / -2

执行摘要

移除测试崩溃计数器的冗余 hasattr 保护

消除死代码,简化测试辅助逻辑。init 已确保属性存在,hasattr 检查不再必要。

简单清理,可安全合并。

讨论亮点

无讨论。

实现拆解

_trigger_crash_for_tests 方法中删除两行:
- if not hasattr(self, "_test_stream_output_count"):
- self._test_stream_output_count = 0
由于 __init__ 已设置为 0,该赋值不再需要。

文件 模块 状态 重要度
python/sglang/srt/managers/scheduler_components/output_streamer.py 调度器 modified 4.47

关键符号

_trigger_crash_for_tests

关键源码片段

python/sglang/srt/managers/scheduler_components/output_streamer.py core-logic

删除 _trigger_crash_for_tests 中的 hasattr fallback,简化测试崩溃计数器逻辑。

# python/sglang/srt/managers/scheduler_components/output_streamer.py
# __init__ 已经设置了 self._test_stream_output_count = 0,因此 hasattr 检查是冗余的。
def _trigger_crash_for_tests(self, crash_threshold: int):
    # Crash trigger: crash after stream_output is called N times
    # This is used for testing purposes.
    self._test_stream_output_count += 1
    if self._test_stream_output_count >= crash_threshold:
        raise RuntimeError(
            f"Test crash after stream_output called {self._test_stream_output_count} times"
        )

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

风险极低:属性已在 init 中初始化,删除 hasattr 不会改变行为。

仅影响测试崩溃触发逻辑,无用户可见影响。

低风险

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论