Skip to content

fix: remove nest_asyncio dependency for Python 3.12+ compatibility#637

Open
Kubudak90 wants to merge 2 commits intocoinbase:mainfrom
Kubudak90:fix/remove-nest-asyncio
Open

fix: remove nest_asyncio dependency for Python 3.12+ compatibility#637
Kubudak90 wants to merge 2 commits intocoinbase:mainfrom
Kubudak90:fix/remove-nest-asyncio

Conversation

@Kubudak90
Copy link
Copy Markdown

Summary

Fixes #591 - Removes the unmaintained nest_asyncio library which is incompatible with Python 3.12+ and modern uvicorn.

Problem

nest_asyncio monkey-patches asyncio.run() with a signature that doesn't support the loop_factory parameter introduced in Python 3.12. This causes failures when using modern uvicorn or other async frameworks:

Additionally, nest_asyncio is no longer maintained.

Solution

Replaced nest_asyncio with a modern, non-monkey-patching approach:

  1. Added _is_event_loop_running() - Detects if we're already in an event loop
  2. Updated _run_async() - Handles both sync and async contexts:
    • If in an event loop: Uses asyncio.run_coroutine_threadsafe() for safe execution
    • If not in an event loop: Uses standard asyncio.run()
  3. Removed nest-asyncio from dependencies in pyproject.toml

Changes

  • python/cdp/evm_local_account.py: Removed nest_asyncio, updated async handling
  • python/pyproject.toml: Removed nest-asyncio dependency

Testing

The new implementation maintains backward compatibility while fixing Python 3.12+ issues. The _run_async function is used internally by EvmLocalAccount for signing operations.

Checklist

@cb-heimdall
Copy link
Copy Markdown

cb-heimdall commented Apr 5, 2026

🟡 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 added 2 commits April 6, 2026 08:10
Updates web3 dependency from <=7.10.0 to <8.0.0 to allow the security
fix for GHSA-5hr4-253g-cpx2 (SSRF via CCIP Read) which shipped in
web3.py v7.15.0.

Fixes coinbase#636
…ility

Replace nest_asyncio with a thread-based approach for running async code
from synchronous contexts. This fixes compatibility issues with Python 3.12+
and modern uvicorn which use loop_factory parameter that nest_asyncio
 doesn't support.

Changes:
- Remove nest_asyncio dependency from pyproject.toml
- Update _run_async() to use ThreadPoolExecutor when inside a running event loop
- This avoids global asyncio monkey-patching while maintaining Jupyter notebook support

Fixes coinbase#591
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