Skip to content

fix: make nest_asyncio optional for Python 3.12+ compatibility#640

Closed
Kubudak90 wants to merge 1 commit into
coinbase:mainfrom
Kubudak90:fix-nest-asyncio-python312
Closed

fix: make nest_asyncio optional for Python 3.12+ compatibility#640
Kubudak90 wants to merge 1 commit into
coinbase:mainfrom
Kubudak90:fix-nest-asyncio-python312

Conversation

@Kubudak90

Copy link
Copy Markdown

Summary

Fixes #591

nest_asyncio is incompatible with Python 3.12+ because its patched asyncio.run() doesn't support the loop_factory parameter used by modern uvicorn and other async frameworks.

Problem

When using Python 3.12+ with uvicorn, importing cdp triggers nest_asyncio.apply() which patches asyncio.run. This breaks uvicorn's server startup which requires the loop_factory parameter.

Error:

Solution

  • Make nest_asyncio import and apply() optional with proper error handling
  • Skip nest_asyncio for Python 3.12+ to preserve loop_factory support
  • Update _run_async() to handle both nested and non-nested loop scenarios gracefully

Changes

  • python/cdp/evm_local_account.py:
    • Conditional import of nest_asyncio
    • Skip apply() for Python 3.12+
    • Improved _run_async() with get_running_loop() and proper fallback

Testing

  • Test with Python 3.10/3.11 (nest_asyncio applied)
  • Test with Python 3.12+ (nest_asyncio skipped)
  • Verify uvicorn compatibility
  • Run existing test suite

nest_asyncio is incompatible with Python 3.12+ due to its patched asyncio.run()
not supporting the loop_factory parameter used by modern uvicorn.

Changes:
- Make nest_asyncio import and apply() optional with proper error handling
- Skip nest_asyncio for Python 3.12+ to avoid breaking loop_factory support
- Update _run_async() to handle both nested and non-nested loop scenarios

Fixes coinbase#591
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@Kubudak90

Copy link
Copy Markdown
Author

Closing in favor of #637 which has a more comprehensive solution

@Kubudak90 Kubudak90 closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Python: Move away from nest_async (is not compatible with modern Python) and is unmaintained.

2 participants