Skip to content

fix(helpers): use asyncio.get_running_loop() inside async methods#3289

Open
Ghraven wants to merge 1 commit into
openai:mainfrom
Ghraven:fix/helpers-get-running-loop
Open

fix(helpers): use asyncio.get_running_loop() inside async methods#3289
Ghraven wants to merge 1 commit into
openai:mainfrom
Ghraven:fix/helpers-get-running-loop

Conversation

@Ghraven
Copy link
Copy Markdown

@Ghraven Ghraven commented May 20, 2026

What

Three async methods in src/openai/helpers/ call asyncio.get_event_loop() from inside a running coroutine:

  • LocalAudioPlayer.play (local_audio_player.py)
  • LocalAudioPlayer.play_stream (local_audio_player.py)
  • Microphone.record (microphone.py)

Why it matters

Since Python 3.10, calling asyncio.get_event_loop() when there is no current event loop is deprecated, and calling it from within a coroutine to obtain the running loop emits a DeprecationWarning. The documented replacement for code that runs inside a coroutine is asyncio.get_running_loop().

Fix

# Before
loop = asyncio.get_event_loop()
# After
loop = asyncio.get_running_loop()

In all three cases the loop is obtained inside an async def and only used for run_in_executor / call_soon_threadsafe, so there is always a running loop and behavior is unchanged. This just removes the deprecation and makes the intent explicit.

Scope

Three one-line changes in src/openai/helpers/ (a hand-maintained, non-generated path). Files still parse and import. Happy to adjust if you would prefer a different approach.

LocalAudioPlayer.play/play_stream and Microphone.record call
asyncio.get_event_loop() while already running inside a coroutine.
Since Python 3.10 that emits a DeprecationWarning, and the documented
correct call within a running loop is asyncio.get_running_loop().
The loop is only used for run_in_executor / call_soon_threadsafe, so
behavior is unchanged on a running loop.
@Ghraven Ghraven requested a review from a team as a code owner May 20, 2026 18:53
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