Skip to content

fix: use per-thread persistent event loop - #8

Merged
zurfjereluhmie merged 1 commit into
mainfrom
fix/event-loop-closed-per-thread-loop
Mar 30, 2026
Merged

fix: use per-thread persistent event loop#8
zurfjereluhmie merged 1 commit into
mainfrom
fix/event-loop-closed-per-thread-loop

Conversation

@zurfjereluhmie

Copy link
Copy Markdown
Owner

No description provided.

…losed'

asyncio.run() creates a new event loop and closes it after each call.
Async I/O libraries (httpx/anyio) schedule transport cleanup via
loop.call_soon() after the coroutine returns; if the loop is already
closed this raises 'RuntimeError: Event loop is closed' for every task
invocation after the first successful one.

Replace asyncio.run() with a threading.local()-backed helper that keeps
one event loop alive per worker thread for the lifetime of the
experiment run. Phoenix's ThreadPoolExecutor workers each get their own
loop, which stays open across all example calls on that thread.

Add a regression test that calls the wrapped task twice on the same
thread to verify the loop is not closed between invocations.
@zurfjereluhmie
zurfjereluhmie merged this pull request into main Mar 30, 2026
1 check passed
@zurfjereluhmie
zurfjereluhmie deleted the fix/event-loop-closed-per-thread-loop branch March 30, 2026 12:31
@zurfjereluhmie zurfjereluhmie changed the title Fix event loop closed per thread loop fix: use per-thread persistent event loop Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant