Skip to content

Commit b1c06b4

Browse files
committed
FIX: Fix multiple calls to start live thread
1 parent 9954f73 commit b1c06b4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#### Bug fixes
99
- Fixed an issue receiving multiple DBN v1 `ErrorMsg` in the `Live` client would cause an `InvalidState` error
10+
- Fixed an issue where creating `Live` clients in multiple threads could cause a `RuntimeError` upon initialization
1011

1112
## 0.39.2 - 2024-08-13
1213

databento/live/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Live:
6161
"""
6262

6363
_loop = asyncio.new_event_loop()
64+
_lock = threading.Lock()
6465
_thread = threading.Thread(
6566
target=_loop.run_forever,
6667
name="databento_live",
@@ -109,8 +110,9 @@ def __init__(
109110

110111
self._session._user_callbacks.append((self._map_symbol, None))
111112

112-
if not Live._thread.is_alive():
113-
Live._thread.start()
113+
with Live._lock:
114+
if not Live._thread.is_alive():
115+
Live._thread.start()
114116

115117
def __del__(self) -> None:
116118
try:

0 commit comments

Comments
 (0)