Fork server doesn't flush stdout/stderr after preloading modules, potentially leaving buffered data to be inherited by child processes #135335
Labels
stdlib
Python modules in the Lib dir
topic-multiprocessing
type-bug
An unexpected behavior, bug, or error
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
Files
a/__init__.py
repro.py
Reproduction
a
containing the__init__.py
file aboverepro.py
script above, ensuring the module created is onPYTHONPATH
Result
Expected
The output to be the same when stdout is redirected as when it is not.
Analysis
This is due to fork server preloading a module that writes to
stdout
, but not flushing it. When a child process is spawned it inherits the buffered data and spuriously outputs it when it flushes itsstdout
. Note that #126631 prevents__main__
from being preloaded, so at present this will not be triggered by printing from__main__
.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: