gh-98552: flush std streams in the multiprocessing forkserver before fork (#141849)

* flush std streams in the multiprocessing forkserver before fork

* NEWS
This commit is contained in:
Gregory P. Smith 2025-11-22 10:29:51 -08:00 committed by GitHub
parent 08477dbf30
commit 58badb1711
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View file

@ -326,6 +326,7 @@ def sigchld_handler(*_unused):
len(fds)))
child_r, child_w, *fds = fds
s.close()
util._flush_std_streams()
pid = os.fork()
if pid == 0:
# Child

View file

@ -0,0 +1,4 @@
The :mod:`multiprocessing` forkserver process now flushes stdout and stderr
before it forks to avoid the confusion children inheriting any buffered but
not yet written output data. Normally there is none, but when using
:func:`multiprocessing.set_forkserver_preload` there *could* be.