Skip to content

BrokenPipeError via terminalwriter #4375

@blueyed

Description

@blueyed

BrokenPipeErrors should be handled better.

The below exception is from interrupting pytest … | tee /tmp/1 via Ctrl-C.

The pipe is closed, but pytest fails two times loudly while trying to write to it.

This appears to abort any (necessary/useful) shutdown probably, too.

platform linux -- Python 3.6.6, pytest-3.10.1.dev53+g04d955af, py-1.7.0, pluggy-0.7.2.dev27+g1da70c9.d20181107
rootdir: …/Vcs/pytest, inifile: tox.ini
plugins: xdist-1.24.0, forked-0.2, hypothesis-3.71.10, testmon-0.9.13
^CTraceback (most recent call last):
  File "…/Vcs/pytest/src/_pytest/config/__init__.py", line 77, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "…/Vcs/pluggy/pluggy/hooks.py", line 284, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "…/Vcs/pluggy/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/Vcs/pluggy/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "…/Vcs/pluggy/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "…/Vcs/pluggy/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "…/Vcs/pluggy/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "…/Vcs/pytest/src/_pytest/main.py", line 217, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "…/Vcs/pytest/src/_pytest/main.py", line 210, in wrap_session
    session=session, exitstatus=session.exitstatus
  File "…/Vcs/pluggy/pluggy/hooks.py", line 284, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "…/Vcs/pluggy/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/Vcs/pluggy/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "…/Vcs/pluggy/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "…/Vcs/pytest/src/_pytest/terminal.py", line 631, in pytest_sessionfinish
    self._tw.line("")
  File "…/Vcs/pytest/.venv/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 273, in line
    self.write('\n')
  File "…/Vcs/pytest/.venv/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 256, in write
    write_out(self._file, markupmsg)
  File "…/Vcs/pytest/.venv/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 421, in write_out
    fil.flush()
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "…/Vcs/pytest/.venv/bin/pytest", line 11, in <module>
    load_entry_point('pytest', 'console_scripts', 'pytest')()
  File "…/Vcs/pytest/src/_pytest/config/__init__.py", line 79, in main
    config._ensure_unconfigure()
  File "…/Vcs/pytest/src/_pytest/config/__init__.py", line 634, in _ensure_unconfigure
    self.hook.pytest_unconfigure(config=self)
  File "…/Vcs/pluggy/pluggy/hooks.py", line 284, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "…/Vcs/pluggy/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/Vcs/pluggy/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "…/Vcs/pluggy/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "…/Vcs/pluggy/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "…/Vcs/pluggy/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "…/Vcs/pytest/src/_pytest/terminal.py", line 661, in pytest_unconfigure
    self._report_keyboardinterrupt()
  File "…/Vcs/pytest/src/_pytest/terminal.py", line 666, in _report_keyboardinterrupt
    self.write_sep("!", msg)
  File "…/Vcs/pytest/src/_pytest/terminal.py", line 318, in write_sep
    self.ensure_newline()
  File "…/Vcs/pytest/src/_pytest/terminal.py", line 287, in ensure_newline
    self._tw.line()
  File "…/Vcs/pytest/.venv/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 273, in line
    self.write('\n')
  File "…/Vcs/pytest/.venv/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 256, in write
    write_out(self._file, markupmsg)
  File "…/Vcs/pytest/.venv/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 421, in write_out
    fil.flush()
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

Metadata

Metadata

Assignees

Labels

topic: reportingrelated to terminal output and user-facing messages and errorstype: bugproblem that needs to be addressed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions