Close this stream. If ``exc_info`` is true, set the ``error`` attribute to the current exception from `sys.exc_info` (or if ``exc_info`` is a tuple, use that instead of `sys.exc_info`).
(
self,
exc_info: Union[
None,
bool,
BaseException,
Tuple[
"Optional[Type[BaseException]]",
Optional[BaseException],
Optional[TracebackType],
],
] = False,
)
| 558 | self._maybe_add_error_listener() |
| 559 | |
| 560 | def close( |
| 561 | self, |
| 562 | exc_info: Union[ |
| 563 | None, |
| 564 | bool, |
| 565 | BaseException, |
| 566 | Tuple[ |
| 567 | "Optional[Type[BaseException]]", |
| 568 | Optional[BaseException], |
| 569 | Optional[TracebackType], |
| 570 | ], |
| 571 | ] = False, |
| 572 | ) -> None: |
| 573 | """Close this stream. |
| 574 | |
| 575 | If ``exc_info`` is true, set the ``error`` attribute to the current |
| 576 | exception from `sys.exc_info` (or if ``exc_info`` is a tuple, |
| 577 | use that instead of `sys.exc_info`). |
| 578 | """ |
| 579 | if not self.closed(): |
| 580 | if exc_info: |
| 581 | if isinstance(exc_info, tuple): |
| 582 | self.error = exc_info[1] |
| 583 | elif isinstance(exc_info, BaseException): |
| 584 | self.error = exc_info |
| 585 | else: |
| 586 | exc_info = sys.exc_info() |
| 587 | if any(exc_info): |
| 588 | self.error = exc_info[1] |
| 589 | if self._read_until_close: |
| 590 | self._read_until_close = False |
| 591 | self._finish_read(self._read_buffer_size) |
| 592 | elif self._read_future is not None: |
| 593 | # resolve reads that are pending and ready to complete |
| 594 | try: |
| 595 | pos = self._find_read_pos() |
| 596 | except UnsatisfiableReadError: |
| 597 | pass |
| 598 | else: |
| 599 | if pos is not None: |
| 600 | self._read_from_buffer(pos) |
| 601 | if self._state is not None: |
| 602 | self.io_loop.remove_handler(self.fileno()) |
| 603 | self._state = None |
| 604 | self.close_fd() |
| 605 | self._closed = True |
| 606 | self._signal_closed() |
| 607 | |
| 608 | def _signal_closed(self) -> None: |
| 609 | futures = [] # type: List[Future] |
no test coverage detected