From 77f7f3b835cf78d5798290aae2a77a005742abd2 Mon Sep 17 00:00:00 2001 From: Nick Macholl Date: Fri, 14 Jun 2024 15:11:04 -0700 Subject: [PATCH] MOD: Call Live.stop on garbage collection --- CHANGELOG.md | 1 + databento/live/client.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e981d6b..ef57649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ #### Enhancements - Added type alias `TBBOMsg` for `MBP1Msg` +- Instances of the `Live` client will now call `Live.stop` when garbage collected ## 0.36.0 - 2024-06-11 diff --git a/databento/live/client.py b/databento/live/client.py index 846bceb..00e5038 100644 --- a/databento/live/client.py +++ b/databento/live/client.py @@ -121,6 +121,12 @@ def factory() -> _SessionProtocol: if not Live._thread.is_alive(): Live._thread.start() + def __del__(self) -> None: + try: + self.stop() + except ValueError: + pass + def __aiter__(self) -> LiveIterator: return iter(self)