Close the connection gracefully. :param float timeout: Optional timeout value in seconds. .. versionchanged:: 0.14.0 Added the *timeout* parameter.
(self, *, timeout=None)
| 1523 | return self._aborted or not self._protocol.is_connected() |
| 1524 | |
| 1525 | async def close(self, *, timeout=None): |
| 1526 | """Close the connection gracefully. |
| 1527 | |
| 1528 | :param float timeout: |
| 1529 | Optional timeout value in seconds. |
| 1530 | |
| 1531 | .. versionchanged:: 0.14.0 |
| 1532 | Added the *timeout* parameter. |
| 1533 | """ |
| 1534 | try: |
| 1535 | if not self.is_closed(): |
| 1536 | await self._protocol.close(timeout) |
| 1537 | except (Exception, asyncio.CancelledError): |
| 1538 | # If we fail to close gracefully, abort the connection. |
| 1539 | self._abort() |
| 1540 | raise |
| 1541 | finally: |
| 1542 | self._cleanup() |
| 1543 | |
| 1544 | def terminate(self): |
| 1545 | """Terminate the connection without waiting for pending data.""" |