Skip to content

Improved Trio support #946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

agronholm
Copy link

  • Removed the asyncio-only parametrization of the anyio_backend except for test_ws, as websockets doesn't support Trio yet
  • Try to close async generators explicitly where possible
  • Changed nesting order for more predictable closing of async resources
  • Refactored __aenter__ and __aexit__ in some cases to exit the task group if there's a problem during initialization
  • Fixed test failures in client/test_auth.py where an async fixture was used in sync tests
  • Fixed subtle bug in SimpleEventStore where retrieving the stream ID was timing-dependent
  • Added typing-extensions to dependencies, as the code already imported it unconditionally

Motivation and Context

This was requested at https://github.com/anthropics/oss-collab/issues/60.

How Has This Been Tested?

No.

Breaking Changes

No.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

* Removed the asyncio-only parametrization of the anyio_backend except for test_ws, as `websockets` doesn't support Trio yet
* Try to close async generators explicitly where possible
* Changed nesting order for more predictable closing of async resources
* Refactored `__aenter__` and `__aexit__` in some cases to exit the task group if there's a problem during initialization
* Fixed test failures in client/test_auth.py where an async fixture was used in sync tests
* Fixed subtle bug in `SimpleEventStore` where retrieving the stream ID was timing-dependent
Comment on lines +127 to +129
# This is to avoid test failures on Trio due to httpx's failure to explicitly close
# async generators
"ignore::pytest.PytestUnraisableExceptionWarning"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we solve those? Why this doesn't happen on asyncio?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trio considers implicit async generator finalization a bad practice and emits a warning. Pytest turns this into an unraisable exception warning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way to fix this is to fix the problem in httpcore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would the fix in httpcore look like?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is not resource warning anyway, I'm okay with it. I read it wrongly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could just make a PR against httpcore if you're willing to review it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can review it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it needs changes in httpx as well. I'll know the full picture once I have the tests passing locally.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changes are required?

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.

3 participants