fix(helpers): use asyncio.get_running_loop() inside async methods#3289
Open
Ghraven wants to merge 1 commit into
Open
fix(helpers): use asyncio.get_running_loop() inside async methods#3289Ghraven wants to merge 1 commit into
Ghraven wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three
asyncmethods insrc/openai/helpers/callasyncio.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 aDeprecationWarning. The documented replacement for code that runs inside a coroutine isasyncio.get_running_loop().Fix
In all three cases the loop is obtained inside an
async defand only used forrun_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.