Close the connection gracefully. :param float timeout: Optional timeout value in seconds. .. versionchanged:: 0.14.0 Added the *timeout* parameter.
(self, *, timeout=None)
| 1500 | return self._aborted or not self._protocol.is_connected() |
| 1501 | |
| 1502 | async def close(self, *, timeout=None): |
| 1503 | """Close the connection gracefully. |
| 1504 | |
| 1505 | :param float timeout: |
| 1506 | Optional timeout value in seconds. |
| 1507 | |
| 1508 | .. versionchanged:: 0.14.0 |
| 1509 | Added the *timeout* parameter. |
| 1510 | """ |
| 1511 | try: |
| 1512 | if not self.is_closed(): |
| 1513 | await self._protocol.close(timeout) |
| 1514 | except (Exception, asyncio.CancelledError): |
| 1515 | # If we fail to close gracefully, abort the connection. |
| 1516 | self._abort() |
| 1517 | raise |
| 1518 | finally: |
| 1519 | self._cleanup() |
| 1520 | |
| 1521 | def terminate(self): |
| 1522 | """Terminate the connection without waiting for pending data.""" |