Skip to content

Commit

Permalink
asyncio.get_event_loop() returns a new event loop only if called fr…
Browse files Browse the repository at this point in the history
…om the main thread. This causes problems and also this function is not recommended by python docs. They recommend to use `asyncio.get_running_loop()`
  • Loading branch information
megatron6000 committed Apr 18, 2024
1 parent 79a0b38 commit 86104f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion allms/models/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ def __init__(
raise ValueError("max_output_tokens has to be lower than model_total_max_tokens")

self._llm = self._create_llm()
self._event_loop = event_loop if event_loop is not None else asyncio.get_event_loop()

if not event_loop:
try:
event_loop = asyncio.get_running_loop()
except RuntimeError as error:
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
self._event_loop = event_loop

self._predict_example = create_base_retry_decorator(
error_types=[
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "allms"
version = "1.0.2"
version = "1.0.3"
description = ""
authors = ["Allegro Opensource <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 86104f9

Please sign in to comment.