mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
fix(cli): replace get_event_loop() with get_running_loop() to silence RuntimeWarning in process_loop thread (#19285)
This commit is contained in:
parent
2c1921241c
commit
edbbc96b55
2 changed files with 143 additions and 2 deletions
14
cli.py
14
cli.py
|
|
@ -1408,7 +1408,13 @@ def _cprint(text: str):
|
|||
|
||||
import asyncio as _asyncio
|
||||
try:
|
||||
current_loop = _asyncio.get_event_loop_policy().get_event_loop()
|
||||
# Use get_running_loop() instead of get_event_loop() to avoid the
|
||||
# DeprecationWarning / RuntimeWarning emitted by Python 3.10+ when
|
||||
# get_event_loop() is called from a thread that has no current event
|
||||
# loop set (e.g. the process_loop background thread). Fixes #19285.
|
||||
current_loop = _asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
current_loop = None
|
||||
except Exception:
|
||||
current_loop = None
|
||||
# Same thread as the app's loop → safe to print directly.
|
||||
|
|
@ -12190,8 +12196,12 @@ class HermesCLI:
|
|||
# Set the custom handler on prompt_toolkit's event loop
|
||||
try:
|
||||
import asyncio as _aio
|
||||
_loop = _aio.get_event_loop()
|
||||
# Use get_running_loop() to avoid DeprecationWarning on
|
||||
# Python 3.10+ when called outside an async context.
|
||||
_loop = _aio.get_running_loop()
|
||||
_loop.set_exception_handler(_suppress_closed_loop_errors)
|
||||
except RuntimeError:
|
||||
pass # No running loop -- nothing to patch
|
||||
except Exception:
|
||||
pass
|
||||
app.run()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue