You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
multiprocessing.Process depends on sys.stdout being open #72513
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2017-10-22.10:27:53.597>created_at=<Date2016-10-01.11:45:34.763>labels= ['3.7', 'type-bug', 'library']
title='multiprocessing.Process depends on sys.stdout being open'updated_at=<Date2017-10-22.10:27:53.595>user='https://github.com/ProgVal'
Traceback (most recent call last):
File "foo.py", line 10, in <module>
p.start()
File "/usr/lib/python3.5/multiprocessing/process.py", line 105, in startself._popen =self._Popen(self)
File "/usr/lib/python3.5/multiprocessing/context.py", line 212, in _Popenreturn _default_context.get_context().Process._Popen(process_obj)
File "/usr/lib/python3.5/multiprocessing/context.py", line 267, in _Popenreturn Popen(process_obj)
File "/usr/lib/python3.5/multiprocessing/popen_fork.py", line 17, in __init__
sys.stdout.flush()
ValueError: I/O operation on closed file.
This bug has been reported to me on a daemonized program (written prior to PEP-3143).
New changeset daeefd2 by Antoine Pitrou in branch 'master': bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (bpo-4073) daeefd2
New changeset 34ef6da by Antoine Pitrou in branch '3.6':
[3.6] bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (GH-4073). (bpo-4075) 34ef6da
Hello , I met some error when using multiprocessing
Process.start() raises BrokenPipeError: [Errno 32] Broken pipe when stdout is a pipe with a dead read end — _flush_std_streams() does not catch OSError
If sys.stdout holds unflushed buffered data and its pipe's read end is gone, sys.stdout.flush() raises BrokenPipeError, which propagates out of Process.start().
importos, sys, multiprocessingdeftarget():
passif__name__=="__main__":
# Simulate a scheduler-launched process whose stdout reader exited.r, w=os.pipe()
os.dup2(w, 1) # fd 1 -> the pipeos.close(r) # read end gone -> broken pipeos.close(w) # fd 1 keeps the write end alivesys.stdout=os.fdopen(1, "w") # block-buffered (pipe, not a tty)sys.stdout.write("unflushed data") # stays in the userspace bufferp=multiprocessing.Process(target=target)
p.start() # raises BrokenPipeErrorp.join()
How we use: the process was launched over SSH (paramiko exec_command), and the caller closed the channel without draining output
Activity
progval commentedon Oct 1, 2016
Hello,
The following code:
Crashes with:
This bug has been reported to me on a daemonized program (written prior to PEP-3143).
tiagoantao commentedon Oct 2, 2016
I made a small patch for this. This is the first time I submit one, so please be careful with this...
terryjreedy commentedon Oct 7, 2016
Patch looks plausible to me. The flush calls definitely need to be guarded.
tiagoantao commentedon Oct 7, 2016
This is the first patch that I am submitting. More than willing to do any changes deemed necessary...
pitrou commentedon Oct 21, 2017
In bpo-31804, we see that sys.stdout and sys.stderr can sometimes simply be None, so we must check for that too.
pitrou commentedon Oct 22, 2017
New changeset daeefd2 by Antoine Pitrou in branch 'master':
bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (bpo-4073)
daeefd2
pitrou commentedon Oct 22, 2017
New changeset 34ef6da by Antoine Pitrou in branch '3.6':
[3.6] bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (GH-4073). (bpo-4075)
34ef6da
pitrou commentedon Oct 22, 2017
This is now fixed in 3.6 and 3.7. Closing!
betterlch commentedon Sep 14, 2026
Hello , I met some error when using
multiprocessingProcess.start()raisesBrokenPipeError: [Errno 32] Broken pipewhen stdout is a pipe with a dead read end —_flush_std_streams()does not catchOSErrorIf
sys.stdoutholds unflushed buffered data and its pipe's read end is gone,sys.stdout.flush()raisesBrokenPipeError, which propagates out ofProcess.start().How we use: the process was launched over SSH (paramiko exec_command), and the caller closed the channel without draining output