From b1c06b4d87c5e0bf7482e33a898ede2ef0085ebf Mon Sep 17 00:00:00 2001 From: Nick Macholl Date: Thu, 15 Aug 2024 15:31:31 -0700 Subject: [PATCH] FIX: Fix multiple calls to start live thread --- CHANGELOG.md | 1 + databento/live/client.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 496be0b..962fc68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ #### Bug fixes - Fixed an issue receiving multiple DBN v1 `ErrorMsg` in the `Live` client would cause an `InvalidState` error +- Fixed an issue where creating `Live` clients in multiple threads could cause a `RuntimeError` upon initialization ## 0.39.2 - 2024-08-13 diff --git a/databento/live/client.py b/databento/live/client.py index 224984b..978b867 100644 --- a/databento/live/client.py +++ b/databento/live/client.py @@ -61,6 +61,7 @@ class Live: """ _loop = asyncio.new_event_loop() + _lock = threading.Lock() _thread = threading.Thread( target=_loop.run_forever, name="databento_live", @@ -109,8 +110,9 @@ def __init__( self._session._user_callbacks.append((self._map_symbol, None)) - if not Live._thread.is_alive(): - Live._thread.start() + with Live._lock: + if not Live._thread.is_alive(): + Live._thread.start() def __del__(self) -> None: try: