Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiprocessing.Process depends on sys.stdout being open #72513

Closed
progval mannequin opened this issue Oct 1, 2016 · 8 comments
Closed

multiprocessing.Process depends on sys.stdout being open #72513

progval mannequin opened this issue Oct 1, 2016 · 8 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@progval
Copy link
Mannequin

progval mannequin commented Oct 1, 2016

BPO 28326
Nosy @terryjreedy, @pitrou, @tiagoantao, @progval, @applio, @Mariatta, @glolol
PRs
  • bpo-28326: Fixes multiprocessing.Process depends on sys.stdout being open #1410
  • bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. #4073
  • [3.6] bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (GH-4073).  #4075
  • Files
  • mp.patch: Patch with test case
  • 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 = None
    closed_at = <Date 2017-10-22.10:27:53.597>
    created_at = <Date 2016-10-01.11:45:34.763>
    labels = ['3.7', 'type-bug', 'library']
    title = 'multiprocessing.Process depends on sys.stdout being open'
    updated_at = <Date 2017-10-22.10:27:53.595>
    user = 'https://github.com/ProgVal'

    bugs.python.org fields:

    activity = <Date 2017-10-22.10:27:53.595>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-22.10:27:53.597>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2016-10-01.11:45:34.763>
    creator = 'Valentin.Lorentz'
    dependencies = []
    files = ['44919']
    hgrepos = []
    issue_num = 28326
    keywords = ['patch']
    message_count = 8.0
    messages = ['277807', '277849', '278271', '278273', '304713', '304737', '304740', '304741']
    nosy_count = 7.0
    nosy_names = ['terry.reedy', 'pitrou', 'tiagoantao', 'Valentin.Lorentz', 'davin', 'Mariatta', 'tacocat']
    pr_nums = ['1410', '4073', '4075']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28326'
    versions = ['Python 3.6', 'Python 3.7']

    @progval
    Copy link
    Mannequin Author

    progval mannequin commented Oct 1, 2016

    Hello,

    The following code:

    import sys
    import multiprocessing
    
    sys.stdout.close()
    
    def foo():
        pass
    
    p = multiprocessing.Process(target=foo)
    p.start()

    Crashes with:

    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 start
        self._popen = self._Popen(self)
      File "/usr/lib/python3.5/multiprocessing/context.py", line 212, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)
      File "/usr/lib/python3.5/multiprocessing/context.py", line 267, in _Popen
        return 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).

    @progval progval mannequin added the stdlib Python modules in the Lib dir label Oct 1, 2016
    @tiagoantao
    Copy link
    Mannequin

    tiagoantao mannequin commented 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
    Copy link
    Member

    Patch looks plausible to me. The flush calls definitely need to be guarded.

    @terryjreedy terryjreedy added the type-bug An unexpected behavior, bug, or error label Oct 7, 2016
    @tiagoantao
    Copy link
    Mannequin

    tiagoantao mannequin commented Oct 7, 2016

    This is the first patch that I am submitting. More than willing to do any changes deemed necessary...

    @tiagoantao tiagoantao mannequin added the 3.7 (EOL) end of life label May 3, 2017
    @pitrou
    Copy link
    Member

    pitrou commented 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
    Copy link
    Member

    pitrou commented 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
    Copy link
    Member

    pitrou commented 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
    Copy link
    Member

    pitrou commented Oct 22, 2017

    This is now fixed in 3.6 and 3.7. Closing!

    @pitrou pitrou closed this as completed Oct 22, 2017
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants