This wrapper is used to catch and suppress BrokenPipeErrors resulting from ``.flush()`` being called on broken pipe during the shutdown/final-GC of the Python interpreter. Notably ``.flush()`` is always called on ``sys.stdout`` and ``sys.stderr``. So as to have minimal impact on any
| 520 | |
| 521 | |
| 522 | class PacifyFlushWrapper: |
| 523 | """This wrapper is used to catch and suppress BrokenPipeErrors resulting |
| 524 | from ``.flush()`` being called on broken pipe during the shutdown/final-GC |
| 525 | of the Python interpreter. Notably ``.flush()`` is always called on |
| 526 | ``sys.stdout`` and ``sys.stderr``. So as to have minimal impact on any |
| 527 | other cleanup code, and the case where the underlying file is not a broken |
| 528 | pipe, all calls and attributes are proxied. |
| 529 | """ |
| 530 | |
| 531 | wrapped: t.IO[t.Any] |
| 532 | |
| 533 | def __init__(self, wrapped: t.IO[t.Any]) -> None: |
| 534 | self.wrapped = wrapped |
| 535 | |
| 536 | def flush(self) -> None: |
| 537 | try: |
| 538 | self.wrapped.flush() |
| 539 | except OSError as e: |
| 540 | import errno |
| 541 | |
| 542 | if e.errno != errno.EPIPE: |
| 543 | raise |
| 544 | |
| 545 | def __getattr__(self, attr: str) -> t.Any: |
| 546 | return getattr(self.wrapped, attr) |
| 547 | |
| 548 | |
| 549 | def _detect_program_name( |
no outgoing calls
no test coverage detected
searching dependent graphs…