Skip to content

broken pipe tracebacks #71

@jeremymcrae

Description

@jeremymcrae

Great package, thanks!

I noticed the CLI tool gives traceback info when it encounters a broken pipe, which seems unnecessary. E.g.

python -m zlib_ng.gzip_ng -c -d FILE.gz | head -1 will produce a traceback like:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/conda/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/opt/conda/lib/python3.10/site-packages/zlib_ng/gzip_ng.py", line 317, in <module>
    main()
  File "/opt/conda/lib/python3.10/site-packages/zlib_ng/gzip_ng.py", line 306, in main
    shutil.copyfileobj(in_file, out_file, args.buffer_size)
  File "/opt/conda/lib/python3.10/shutil.py", line 198, in copyfileobj
    fdst_write(buf)
BrokenPipeError: [Errno 32] Broken pipe

whereas gzip -c -d FILE.gz | head -n 1 would halt without any extra lines. Having the traceback isn't really a problem, but I've suppressed things like this before e.g.

try:
    run_stuff(*args)
except (KeyboardInterrupt, BrokenPipeError):
    devnull = os.open(os.devnull, os.O_WRONLY)
    os.dup2(devnull, sys.stdout.fileno())
    sys.exit(0)

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