fix(tmwebdriver): wrap master prints in safe_print to survive stdout revoke (closes #672)#673
Open
Kailigithub wants to merge 1 commit into
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the OS revokes the master process's stdout (observed on macOS as
BrokenPipeErroron everyprint()), the WebSocket connection to the Chrome extension drops within ~1 second ofext_ready, andweb_scanfalls back to a cached session list — the user sees historical tab data instead of the live browser state.Mirror the
safe_printpattern already used inga.pyby wrapping all 11 rawprint()call sites inTMWebDriver.pywithsafe_print, which swallowsBrokenPipeErrorand lets the WebSocket read loop keep serving the extension.Changes
TMWebDriver.py:7-9— definesafe_printat module top (same body asga.py:12-14)TMWebDriver.py:36,63,102,137,154,155,158,165,173,177,189,203,278,279,281— replaceprint(withsafe_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— passesRegression test:
/tmp/test_issue_672_safe_print.pycovers 6 cases:safe_printcall passes through tobuiltins.printBrokenPipeErrorfromprintis swallowed (matches the bug)OSErroris also swallowed (broader case)safe_printis defined inTMWebDriver.pywith the expected bodyprint(call sites remain outside thedefblocksafe_print(call sites exist (the 11 that were rawprint)Test fails on
main(assertion:"def safe_print" in srcreturnsFalse), passes with this fix. Confirmed via thegit stash push / python3 / git stash popthree-step dance.Related
safe_printbody is taken fromga.py:12-14— keeping the pattern consistent across modules.os.dup2(devnull, sys.stdout.fileno())); I went with the simpler swallow-and-continue approach because the read loop recovers naturally once the nextprintreturns silently, and matches the existingga.pystyle.Closes #672