When a custom stdout or stderr splitter processes data or flushes asynchronously, PythonShell can emit close and invoke its end() 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 be close → end callback → message("tail"); it should be message("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 close barrier, 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:
New asynchronous-output regressions before the fix: 8 fail with output arriving after completion.
Focused suite after the fix: 9 pass.
Full npm test: 52 pass.
Prettier and git diff --check: pass; generated TypeScript declarations match master.
For the full suite, PYTHONPYCACHEPREFIX was 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.
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
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 close and invoke its end() 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 be close → end callback → message("tail"); it should be message("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 close barrier, 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:
For the full suite, PYTHONPYCACHEPREFIX was 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.