Skip to content

Commit

Permalink
FIX: Fix multiple calls to start live thread
Browse files Browse the repository at this point in the history
  • Loading branch information
nmacholl committed Aug 16, 2024
1 parent 9954f73 commit b1c06b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions databento/live/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Live:
"""

_loop = asyncio.new_event_loop()
_lock = threading.Lock()
_thread = threading.Thread(
target=_loop.run_forever,
name="databento_live",
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b1c06b4

Please sign in to comment.