[issue46492] BrokenPipeError when piping to head (linux)
Roy Assis
report at bugs.python.org
Sun Jan 23 14:48:57 EST 2022
New submission from Roy Assis <royassisg at gmail.com>:
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 at IP111-11-1-111:~/scripts/short-python-scripts$ uname -srm
# Linux 5.4.0-1063-aws x86_64
code execution
--------------
# (scanpyEnv3.8) aaa at 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
----------
components: IO
messages: 411413
nosy: royroy
priority: normal
severity: normal
status: open
title: BrokenPipeError when piping to head (linux)
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46492>
_______________________________________
More information about the Python-bugs-list
mailing list