FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-135335: flush stdout/stderr in forkserver after preloading modules by duaneg · Pull Request #135338 · python/cpython · GitHub

Repository navigation

gh-135335: flush stdout/stderr in forkserver after preloading modules - #135338

Merged
vstinner merged 15 commits into
python:mainfrom
duaneg:gh-135335
Jun 18, 2025
Merged

vstinner merged 15 commits into
python:mainfrom
duaneg:gh-135335

Conversation

duaneg commented Jun 10, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

If a preloaded module writes to stdout or stderr, and the stream is buffered, child processes will inherit the buffered data after forking. Attempt to prevent this by flushing the streams after preload.

…odules

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.
Comment thread Lib/test/mp_preload_flush.py Outdated
duaneg requested a review from efimov-mikhail June 16, 2025 09:06
Comment thread Lib/test/_test_multiprocessing.py Outdated
Comment thread Lib/test/_test_multiprocessing.py Outdated
…use a

not-completely-awful name for the module to test.
Comment thread Lib/test/_test_multiprocessing.py Outdated

efimov-mikhail left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Comment thread Lib/test/_test_multiprocessing.py Outdated
Comment thread Lib/test/_test_multiprocessing.py Outdated
Comment thread Lib/test/mp_preload_flush.py Outdated
duaneg and others added 2 commits June 18, 2025 00:44
Comment thread Lib/test/_test_multiprocessing.py Outdated
Comment thread Lib/test/_test_multiprocessing.py Outdated

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. I just have a last suggestion.

Comment thread Lib/test/mp_preload_flush.py Outdated

efimov-mikhail left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

vstinner merged commit 9877d19 into python:main Jun 18, 2025
vstinner added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Jun 18, 2025

Copy link
Copy Markdown

Thanks @duaneg for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

Copy link
Copy Markdown

Thanks @duaneg for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 18, 2025
…odules (pythonGH-135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.
(cherry picked from commit 9877d19)

Co-authored-by: Duane Griffin <duaneg@dghda.com>
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>

bedevere-app Bot commented Jun 18, 2025

Copy link
Copy Markdown

GH-135670 is a backport of this pull request to the 3.14 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 18, 2025
…odules (pythonGH-135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.
(cherry picked from commit 9877d19)

Co-authored-by: Duane Griffin <duaneg@dghda.com>
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 18, 2025

bedevere-app Bot commented Jun 18, 2025

Copy link
Copy Markdown

GH-135671 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 18, 2025

Copy link
Copy Markdown
Member

Thanks for the bug report and the fix @duaneg.

duaneg commented Jun 18, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews, folks.

vstinner added a commit that referenced this pull request Jun 18, 2025
…modules (GH-135338) (#135671)

gh-135335: flush stdout/stderr in forkserver after preloading modules (GH-135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.
(cherry picked from commit 9877d19)

Co-authored-by: Duane Griffin <duaneg@dghda.com>
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Jun 18, 2025
…modules (GH-135338) (#135670)

gh-135335: flush stdout/stderr in forkserver after preloading modules (GH-135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.
(cherry picked from commit 9877d19)

Co-authored-by: Duane Griffin <duaneg@dghda.com>
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>

efimov-mikhail commented Jun 18, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

Thanks for thorough working on this PR!
Looking forward for the next one!

duaneg commented Jun 18, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for thorough working on this PR! Looking forward for the next one!

Well, as it happens, I would love #132574 to get a review 🙂

It is a very simple bug and fix: an off-by-one error, that allows an out-of-bounds read, which affects basic string operations like replace(), and has been in our code base ~forever.

Copy link
Copy Markdown
Member

Ok, I'll take a look.

lkollar pushed a commit to lkollar/cpython that referenced this pull request Jun 19, 2025
…odules (python#135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
…odules (python#135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
…odules (python#135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
…odules (python#135338)

If a preloaded module writes to stdout or stderr, and the stream is buffered,
child processes will inherit the buffered data after forking. Attempt to
prevent this by flushing the streams after preload.

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL