This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: multiprocessing.Process depends on sys.stdout being open
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mariatta, Valentin.Lorentz, davin, pitrou, tacocat, terry.reedy, tiagoantao
Priority: normal Keywords: patch

Created on 2016-10-01 11:45 by Valentin.Lorentz, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
mp.patch tiagoantao, 2016-10-02 04:38 Patch with test case review
Pull Requests
URL Status Linked Edit
PR 1410 closed tiagoantao, 2017-05-03 02:29
PR 4073 merged pitrou, 2017-10-22 09:06
PR 4075 merged pitrou, 2017-10-22 09:46
Messages (8)
msg277807 - (view) Author: ProgVal (Valentin.Lorentz) Date: 2016-10-01 11:45

The following code:

import sys
import multiprocessing


def foo():

p = multiprocessing.Process(target=foo)

Crashes with:

Traceback (most recent call last):
  File "", line 10, in <module>
  File "/usr/lib/python3.5/multiprocessing/", line 105, in start
    self._popen = self._Popen(self)
  File "/usr/lib/python3.5/multiprocessing/", line 212, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/lib/python3.5/multiprocessing/", line 267, in _Popen
    return Popen(process_obj)
  File "/usr/lib/python3.5/multiprocessing/", line 17, in __init__
ValueError: I/O operation on closed file.

This bug has been reported to me on a daemonized program (written prior to PEP 3143).
msg277849 - (view) Author: Tiago Antao (tiagoantao) * Date: 2016-10-02 04:38
I made a small patch for this. This is the first time I submit one, so please be careful with this...
msg278271 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-10-07 21:37
Patch looks plausible to me.  The flush calls definitely need to be guarded.
msg278273 - (view) Author: Tiago Antao (tiagoantao) * Date: 2016-10-07 21:51
This is the first patch that I am submitting. More than willing to do any changes deemed necessary...
msg304713 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-21 16:57
In issue31804, we see that sys.stdout and sys.stderr can sometimes simply be None, so we must check for that too.
msg304737 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-22 09:40
New changeset daeefd2e049b74340307481112a39f77de0f4769 by Antoine Pitrou in branch 'master':
bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (#4073)
msg304740 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-22 10:27
New changeset 34ef6da8f5fb03b83268bd35b77fb2183c748b70 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).  (#4075)
msg304741 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-22 10:27
This is now fixed in 3.6 and 3.7.  Closing!
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72513
2018-03-11 18:15:55pitrouunlinkissue31804 superseder
2017-10-22 10:27:53pitrousetstatus: open -> closed
resolution: fixed
messages: + msg304741

stage: patch review -> resolved
2017-10-22 10:27:15pitrousetmessages: + msg304740
2017-10-22 09:46:42pitrousetpull_requests: + pull_request4045
2017-10-22 09:40:33pitrousetmessages: + msg304737
2017-10-22 09:06:46pitrousetpull_requests: + pull_request4043
2017-10-21 16:57:54pitrousetnosy: + pitrou

messages: + msg304713
versions: - Python 3.5
2017-10-20 20:39:55pitroulinkissue31804 superseder
2017-05-03 02:30:29tiagoantaosetversions: + Python 3.6, Python 3.7
2017-05-03 02:29:16tiagoantaosetpull_requests: + pull_request1515
2016-10-07 21:51:14tiagoantaosetmessages: + msg278273
2016-10-07 21:37:22terry.reedysetnosy: + terry.reedy
messages: + msg278271

type: behavior
stage: patch review
2016-10-02 04:38:18tiagoantaosetfiles: + mp.patch

nosy: + tiagoantao
messages: + msg277849

keywords: + patch
2016-10-01 22:47:48tacocatsetnosy: + tacocat
2016-10-01 17:28:22ned.deilysetnosy: + davin
2016-10-01 16:40:35Mariattasetnosy: + Mariatta
2016-10-01 11:45:34Valentin.Lorentzcreate