| 433 | __slots__ = () |
| 434 | |
| 435 | def terminate(self) -> None: |
| 436 | if in_greenlet(): |
| 437 | # in a greenlet; this is the connection was invalidated case. |
| 438 | try: |
| 439 | # try to gracefully close; see #10717 |
| 440 | await_(asyncio.shield(self._terminate_graceful_close())) |
| 441 | except self._terminate_handled_exceptions() as e: |
| 442 | # in the case where we are recycling an old connection |
| 443 | # that may have already been disconnected, close() will |
| 444 | # fail. In this case, terminate |
| 445 | # the connection without any further waiting. |
| 446 | # see issue #8419 |
| 447 | self._terminate_force_close() |
| 448 | if isinstance(e, asyncio.CancelledError): |
| 449 | # re-raise CancelledError if we were cancelled |
| 450 | raise |
| 451 | else: |
| 452 | # not in a greenlet; this is the gc cleanup case |
| 453 | self._terminate_force_close() |
| 454 | |
| 455 | def _terminate_handled_exceptions(self) -> Tuple[Type[BaseException], ...]: |
| 456 | """Returns the exceptions that should be handled when |