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.

Author royroy
Recipients royroy
Date 2022-01-23.19:48:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642967337.45.0.0488818271816.issue46492@roundup.psfhosted.org>
In-reply-to
Content
problem:
-------
Python raises exception when piping to head. Exception is not caught by try except.

code:
----
#sample.py
import sys
from time import sleep

try:
    for line in sys.stdin:
        print(line, flush=True)
        sleep(2)
except:
    print("a")

Environment:
----------
# Python 3.8.12 (default, Oct 12 2021, 13:49:34)
# [GCC 7.5.0] :: Anaconda, Inc. on linux
# (scanpyEnv3.8) aaa@IP111-11-1-111:~/scripts/short-python-scripts$ uname -srm
# Linux 5.4.0-1063-aws x86_64

code execution
--------------
# (scanpyEnv3.8) aaa@IP111-11-1-111:~/scripts/short-python-scripts$ echo "a a a a" | sed s'/ /\n/g' | python ./sample.py | head -3
# a
#
# a
# Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
# BrokenPipeError: [Errno 32] Broken pipe
History
Date User Action Args
2022-01-23 19:48:57royroysetrecipients: + royroy
2022-01-23 19:48:57royroysetmessageid: <1642967337.45.0.0488818271816.issue46492@roundup.psfhosted.org>
2022-01-23 19:48:57royroylinkissue46492 messages
2022-01-23 19:48:57royroycreate