Repository navigation
Isolate concurrent pretty-format streams - #180
Open
rupayon123 wants to merge 1 commit into
Open
rupayon123 wants to merge 1 commit into
rupayon123 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/test_prettier.py">
<violation number="1" location="tests/test_prettier.py:95">
P2: These workers are non-daemon, so a formatter deadlock leaves them alive after the 10-second `join()` and blocks interpreter shutdown. Create them as daemon threads so this regression test fails instead of hanging CI.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
| assert first_entered.wait(5) | ||
| results['second'] = formatter(Second()) | ||
|
|
||
| threads = [Thread(target=format_first), Thread(target=format_second)] |
There was a problem hiding this comment.
P2: These workers are non-daemon, so a formatter deadlock leaves them alive after the 10-second join() and blocks interpreter shutdown. Create them as daemon threads so this regression test fails instead of hanging CI.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/test_prettier.py, line 95:
<comment>These workers are non-daemon, so a formatter deadlock leaves them alive after the 10-second `join()` and blocks interpreter shutdown. Create them as daemon threads so this regression test fails instead of hanging CI.</comment>
<file context>
@@ -61,6 +62,86 @@ def __repr__(self) -> str:
+ assert first_entered.wait(5)
+ results['second'] = formatter(Second())
+
+ threads = [Thread(target=format_first), Thread(target=format_second)]
+ for thread in threads:
+ thread.start()
</file context>
Suggested change
| threads = [Thread(target=format_first), Thread(target=format_second)] | |
| threads = [Thread(target=format_first, daemon=True), Thread(target=format_second, daemon=True)] |
This branch has not been deployed
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.
Two overlapping calls to global
pformator a sharedPrettyFormatcan mix or truncate each other's output. An event-coordinated example producesSecond[1]and2]instead ofFirst[1]andSecond[2]. The existing save/restore logic handles reentrancy but still shares the active stream between threads.Store each call's active stream in a
ContextVarand reset its token infinally. Keep the idle instance stream so existing copy and pickle behavior is preserved. No dependency or lock is added.Validation on macOS arm64:
Other supported CI platforms remain unverified locally. Existing IPython/timer skips and pickle protocol 0/1 errors are unchanged. This does not claim a complete free-threaded optional-extension suite.
Summary by cubic
Fixes concurrent
pformatorPrettyFormatcalls mixing or truncating output by giving each call its own stream via aContextVar, instead of sharing the instance stream between threads._current_streamand resets its token infinally, keeping the idle instance stream for copy and pickle behavior.Written for commit 13bd23d. Summary will update on new commits.