diff --git a/src/websockets/sync/connection.py b/src/websockets/sync/connection.py index 8b9e06257..12046d7ea 100644 --- a/src/websockets/sync/connection.py +++ b/src/websockets/sync/connection.py @@ -226,6 +226,9 @@ def __exit__( else: self.close(CloseCode.INTERNAL_ERROR) + def __del__(self) -> None: + self.close() + def __iter__(self) -> Iterator[Data]: """ Iterate on incoming messages.