Skip to content

fix(tmwebdriver): wrap master prints in safe_print to survive stdout revoke (closes #672)#673

Open
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-672-tmwebdriver-safe-print
Open

fix(tmwebdriver): wrap master prints in safe_print to survive stdout revoke (closes #672)#673
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-672-tmwebdriver-safe-print

Conversation

@Kailigithub

Copy link
Copy Markdown
Contributor

Summary

When the OS revokes the master process's stdout (observed on macOS as BrokenPipeError on every print()), the WebSocket connection to the Chrome extension drops within ~1 second of ext_ready, and web_scan falls back to a cached session list — the user sees historical tab data instead of the live browser state.

Mirror the safe_print pattern already used in ga.py by wrapping all 11 raw print() call sites in TMWebDriver.py with safe_print, which swallows BrokenPipeError and lets the WebSocket read loop keep serving the extension.

Changes

  • TMWebDriver.py:7-9 — define safe_print at module top (same body as ga.py:12-14)
  • TMWebDriver.py:36,63,102,137,154,155,158,165,173,177,189,203,278,279,281 — replace print( with safe_print(

15-line source change in a single file. No public API change; no behavior change for callers when stdout is healthy.

Verification

  • python3 -m py_compile TMWebDriver.py — passes

  • Regression test: /tmp/test_issue_672_safe_print.py covers 6 cases:

    1. Normal safe_print call passes through to builtins.print
    2. BrokenPipeError from print is swallowed (matches the bug)
    3. Generic OSError is also swallowed (broader case)
    4. safe_print is defined in TMWebDriver.py with the expected body
    5. No raw print( call sites remain outside the def block
    6. ≥ 11 safe_print( call sites exist (the 11 that were raw print)

    Test fails on main (assertion: "def safe_print" in src returns False), passes with this fix. Confirmed via the git stash push / python3 / git stash pop three-step dance.

Related

Closes #672

…revoke

When the OS revokes the master process's stdout (observed on
macOS as BrokenPipeError on every print), the WebSocket connection
to the Chrome extension drops within ~1 second of ext_ready, and
web_scan falls back to a cached session list — the user sees
historical tab data instead of the live browser state.

Mirror the safe_print pattern already used in ga.py by wrapping all
11 print() call sites in TMWebDriver.py with safe_print, which
swallows BrokenPipeError and lets the read loop continue serving
the WebSocket connection.

Fixes lsdefine#672
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: TMWebDriver master stdout 被 revoke → print() 抛 BrokenPipeError,导致扩展 WS 连接秒断、web_scan 读取历史脏数据

1 participant