Skip to content

Commit a03cbcd

Browse files
authored
Merge pull request NousResearch#2317 from NousResearch/hermes/hermes-5d6932ba
fix(cron): close abandoned coroutine when asyncio.run() raises RuntimeError
2 parents 9305164 + df67ae7 commit a03cbcd

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

cron/scheduler.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,15 @@ def _deliver_result(job: dict, content: str) -> None:
170170
)
171171

172172
# Run the async send in a fresh event loop (safe from any thread)
173+
coro = _send_to_platform(platform, pconfig, chat_id, wrapped, thread_id=thread_id)
173174
try:
174-
result = asyncio.run(_send_to_platform(platform, pconfig, chat_id, wrapped, thread_id=thread_id))
175+
result = asyncio.run(coro)
175176
except RuntimeError:
176-
# asyncio.run() fails if there's already a running loop in this thread;
177-
# spin up a new thread to avoid that.
177+
# asyncio.run() checks for a running loop before awaiting the coroutine;
178+
# when it raises, the original coro was never started — close it to
179+
# prevent "coroutine was never awaited" RuntimeWarning, then retry in a
180+
# fresh thread that has no running loop.
181+
coro.close()
178182
import concurrent.futures
179183
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
180184
future = pool.submit(asyncio.run, _send_to_platform(platform, pconfig, chat_id, wrapped, thread_id=thread_id))

0 commit comments

Comments
 (0)