fix: skip nest_asyncio on Python 3.12+ to prevent uvicorn loop_factory error#635
Closed
Kubudak90 wants to merge 2 commits into
Closed
fix: skip nest_asyncio on Python 3.12+ to prevent uvicorn loop_factory error#635Kubudak90 wants to merge 2 commits into
Kubudak90 wants to merge 2 commits into
Conversation
…y error nest_asyncio.apply() patches asyncio.run() with a signature that doesn't support the loop_factory parameter added in Python 3.12. This causes uvicorn to fail with: TypeError: _patch_asyncio.<locals>.run() got an unexpected keyword argument 'loop_factory' Fix: Only apply nest_asyncio on Python < 3.12 where the patch is safe. On Python 3.12+, the standard asyncio behavior is preserved. Fixes coinbase#591
🟡 Heimdall Review Status
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
Closing in favor of #637 which has a more comprehensive solution |
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.
Problem
nest_asyncio.apply()patchesasyncio.run()with a signature that doesn't support theloop_factoryparameter added in Python 3.12. This causes uvicorn (and other modern async frameworks) to fail with:This was reported in #591.
Solution
Only apply
nest_asyncioon Python < 3.12 where the patch is safe. On Python 3.12+, the standard asyncio behavior is preserved, allowing uvicorn and other frameworks to use the newloop_factoryparameter.Changes
import sysat the top of the fileimport nest_asyncioinside the version check blocknest_asyncio.apply()call in asys.version_info < (3, 12)conditionTesting
This fix ensures:
Fixes #591