fix: wait for output splitters before completing PythonShell - #335
Open
lonecoding wants to merge 1 commit into
Open
fix: wait for output splitters before completing PythonShell#335lonecoding wants to merge 1 commit into
lonecoding wants to merge 1 commit into
Conversation
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.
When a custom stdout or stderr splitter processes data or flushes asynchronously, PythonShell can emit
closeand invoke itsend()callback before the final output event. A caller that reads its collected messages in the completion callback therefore receives incomplete output. The current order can beclose → end callback → message("tail"); it should bemessage("tail") → close → end callback.Track completion of each active splitter's readable side alongside the existing source-stream and process-exit checks. Keep waiting for the original streams as well, so a splitter that ends early does not truncate the stderr collected for process errors. No public API, dependency, or newline parsing changes.
Regression tests use real Python processes and a child-process
closebarrier, without sleeps or mocked process events. They cover stdout/stderr, asynchronous_transform/_flush, exit codes 0/7, and complete stderr collection when a splitter ends before its source.Validation on macOS arm64, Node.js 22.23.1 and Python 3.9.6:
1cf1bfcac6ccde265bf0ac0e422fc54379941ed0: 43 existing tests pass.npm test: 52 pass.git diff --check: pass; generated TypeScript declarations match master.For the full suite,
PYTHONPYCACHEPREFIXwas set to a writable local directory for Python's syntax-check cache. Windows and Linux were not run locally.Related work checked: #332 changes newline splitting; #329 flushes splitters in its timeout path. The eight asynchronous-output regressions still fail on both current PR heads without this fix. This PR addresses normal process completion, including nonzero exit codes.