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.

classification
Title: tarfile: Exception ignored in (... stdout ...) BrokenPipeError
Type: Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, erlendaasland, ethan.furman, vstinner
Priority: normal Keywords: patch

Created on 2020-03-04 18:03 by vstinner, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
approach.py corona10, 2020-04-08 13:50
bpo-39851.patch corona10, 2020-04-08 14:49
Messages (3)
msg363368 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-04 18:03
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".
msg363419 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-03-05 06:45
I will take look at this issue :)
msg365986 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-04-08 13:50
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
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84032
2020-04-08 14:49:28corona10setfiles: + bpo-39851.patch
keywords: + patch
2020-04-08 13:50:08corona10setfiles: + approach.py

messages: + msg365986
2020-03-05 06:45:43corona10setmessages: + msg363419
2020-03-04 21:42:03erlendaaslandsetnosy: + erlendaasland
2020-03-04 18:08:02xtreaksetnosy: + ethan.furman
2020-03-04 18:03:06vstinnercreate