Skip to content

fix: enhance event loop management and update dependencies#146

Open
lofingv wants to merge 8 commits intoOpenGradient:mainfrom
lofingv:fix/asyncio-loop-management
Open

fix: enhance event loop management and update dependencies#146
lofingv wants to merge 8 commits intoOpenGradient:mainfrom
lofingv:fix/asyncio-loop-management

Conversation

@lofingv
Copy link

@lofingv lofingv commented Feb 5, 2026

Description

This PR improves the stability of the Python SDK by addressing event loop conflicts and refining exception handling.

Key Changes:

  • src/opengradient/client.py:
    • Replaced asyncio.run() with a more robust logic using get_event_loop and nest_asyncio. This fixes crashes when the SDK is used inside existing async frameworks (like FastAPI or Jupyter).
    • Refined the bare except: block in _is_local_model to catch only specific exceptions (AttributeError, TypeError, ValueError).
  • pyproject.toml:
    • Added nest-asyncio to the project dependencies to support the new event loop logic.

Testing:

Verified that the client no longer raises RuntimeError when called from an active event loop.

@lofingv
Copy link
Author

lofingv commented Feb 6, 2026

Resolved merge conflicts in client.py and updated the asyncio loop management logic to support nested loops.

- Added missing scheme_filter parameter to X402Auth.__init__
- Updated async_auth_flow to use scheme_filter in payment requirements selection
- Fixed type hinting for payment_requirements_selector to resolve Copilot warnings
@lofingv
Copy link
Author

lofingv commented Feb 7, 2026

Synced this PR with the latest changes in main. I've applied the asyncio loop management fix to the new AsyncClient structure and updated the X402Auth call to include the new scheme_filter for consistency across the SDK.

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