Skip to content

Crash on broken pipe when being pipelined to head #2193

@izokina

Description

@izokina

The subject :)

% pygmentize -v some_reasonably_long_text_file | head
. . .
the 10 lines go here, and...
. . .
Traceback (most recent call last):
  File "/usr/bin/pygmentize", line 33, in <module>
    sys.exit(load_entry_point('Pygments==2.12.0', 'console_scripts', 'pygmentize')())
  File "/usr/lib/python3.10/site-packages/pygments/cmdline.py", line 638, in main
    return main_inner(parser, argns)
  File "/usr/lib/python3.10/site-packages/pygments/cmdline.py", line 490, in main_inner
    highlight(code, lexer, fmter, outfile)
  File "/usr/lib/python3.10/site-packages/pygments/__init__.py", line 82, in highlight
    return format(lex(code, lexer), formatter, outfile)
  File "/usr/lib/python3.10/site-packages/pygments/__init__.py", line 64, in format
    formatter.format(tokens, outfile)
  File "/usr/lib/python3.10/site-packages/pygments/formatters/terminal256.py", line 250, in format
    return Formatter.format(self, tokensource, outfile)
  File "/usr/lib/python3.10/site-packages/pygments/formatter.py", line 94, in format
    return self.format_unencoded(tokensource, outfile)
  File "/usr/lib/python3.10/site-packages/pygments/formatters/terminal256.py", line 275, in format_unencoded
    outfile.write(on + spl[-1] + off)
  File "/usr/lib/python3.10/codecs.py", line 378, in write
    self.stream.write(data)
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe

Operating system ArchLinux, fresh at the moment.
Python version 3.10.5.
My file is a little more than 100 loc, it may be important for the reproduction. Theoretically :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions