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

tarfile: Exception ignored in (... stdout ...) BrokenPipeError #84032

Closed
vstinner opened this issue Mar 4, 2020 · 4 comments
Closed

tarfile: Exception ignored in (... stdout ...) BrokenPipeError #84032

vstinner opened this issue Mar 4, 2020 · 4 comments
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

vstinner commented Mar 4, 2020

BPO 39851
Nosy @vstinner, @ethanfurman, @corona10, @erlend-aasland
Files
  • approach.py
  • bpo-39851.patch
  • 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 = None
    created_at = <Date 2020-03-04.18:03:06.415>
    labels = ['library', '3.9']
    title = 'tarfile: Exception ignored in (... stdout ...) BrokenPipeError'
    updated_at = <Date 2020-04-08.14:49:28.700>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-04-08.14:49:28.700>
    actor = 'corona10'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-03-04.18:03:06.415>
    creator = 'vstinner'
    dependencies = []
    files = ['49045', '49046']
    hgrepos = []
    issue_num = 39851
    keywords = ['patch']
    message_count = 3.0
    messages = ['363368', '363419', '365986']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'ethan.furman', 'corona10', 'erlendaasland']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39851'
    versions = ['Python 3.9']

    @vstinner
    Copy link
    Member Author

    vstinner commented Mar 4, 2020

    When a stdout pipe is closed on the consumer side, Python logs an exception at exit:

    $ ./python -m tarfile -l archive.tar|true
    Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
    BrokenPipeError: [Errno 32] Broken pipe

    I tried to flush explicitly stdout at exit: it allows to catch BrokenPipeError... but Python still logs the exception, since it triggered by the TextIOWrapper finalizer which tries to flush the file again.

    See also bpo-39828: "json.tool should catch BrokenPipeError".

    @vstinner vstinner added 3.9 only security fixes stdlib Python modules in the Lib dir labels Mar 4, 2020
    @corona10
    Copy link
    Member

    corona10 commented Mar 5, 2020

    I will take look at this issue :)

    @corona10
    Copy link
    Member

    corona10 commented Apr 8, 2020

    Victor,
    I found a way how to deal with it.
    The submitted file will show how it can be handled.

    If you remove the try: finally statement.
    You can see the same stdout which occurred from tarfile

    But I'd like to listen to your opinion before submitting the patch. :)

    ➜ cpython git:(master) ✗ set -o pipefail
    ➜ cpython git:(master) ✗ ./python.exe ttt.py
    test
    hi
    ➜ cpython git:(master) ✗ ./python.exe ttt.py | true
    ➜ cpython git:(master) ✗ echo $?
    32

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    corona10 added a commit to corona10/cpython that referenced this issue Oct 21, 2022
    corona10 added a commit to corona10/cpython that referenced this issue Oct 21, 2022
    @corona10 corona10 added 3.11 only security fixes 3.10 only security fixes 3.12 bugs and security fixes and removed 3.9 only security fixes labels Oct 21, 2022
    @vstinner
    Copy link
    Member Author

    @corona10 proposed #98505 but closed his PR as "invalid patch".

    While the behavior can be improved, I don't think that it's a major issue. I created this issue as a TODO list item, but I failed to find time to look at it. I prefer to close it. If someone wants to propose a fix, please go ahead.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir
    Projects
    Status: Done
    Development

    No branches or pull requests

    2 participants