Skip to content
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

Modernize sniffio integration #124

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

oremanj
Copy link
Member

@oremanj oremanj commented Nov 6, 2023

Use sniffio.thread_local to indicate which async library is running, instead of the deprecated sniffio.current_async_library_cvar. This allows us to remove a number of workarounds for the contextvar being inherited where it shouldn't be, and is also necessary to interoperate with Trio 0.23 which uses the thread-local.

Fixes #123.

Use `sniffio.thread_local` to indicate which async library is running, instead of the deprecated `sniffio.current_async_library_cvar`. This allows us to remove a number of workarounds for the contextvar being inherited where it shouldn't be.
Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

Looks good, I don't have too much familiarity with sniffio/trio-asyncio so can't comment on the code changes, but I have a few comments on meta-changes.

setup.py Show resolved Hide resolved
@@ -56,7 +56,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['pypy-3.7', 'pypy-3.8', 'pypy-3.9', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev', 'pypy-3.8-nightly', 'pypy-3.9-nightly']
python: ['pypy-3.7', 'pypy-3.8', 'pypy-3.9', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.8-nightly', 'pypy-3.9-nightly']
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
python: ['pypy-3.7', 'pypy-3.8', 'pypy-3.9', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.8-nightly', 'pypy-3.9-nightly']
python: ['pypy-3.7', 'pypy-3.8', 'pypy-3.9', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.8-nightly', 'pypy-3.9-nightly']

Maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to do another PR to drop 3.7 and add 3.12 support to CI and the setup.py trove classifiers. For now just wanted to do the minimal thing to get it to build. The error with 3.12-dev is an Ubuntu packaging thing unrelated to trio-asyncio.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I suggested the change cause it looks like the step that fails only runs if the version ends with -dev (probably remnants of setup-python not supporting dev versions?). But totally fair to move it to another PR.

@A5rocks
Copy link
Contributor

A5rocks commented Nov 7, 2023

Generally, it might be nice if sniffio had a warning if both methods of setting async library name are set? Not sure and tbh I should just make an issue on that repo, just running this by you first! (it negates possible perf improvements, though it could be behind an if __debug__ or whatever)

@oremanj
Copy link
Member Author

oremanj commented Nov 7, 2023

Generally, it might be nice if sniffio had a warning if both methods of setting async library name are set?

Trio and trio-asyncio are the only libraries that actually integrate with sniffio, so now that they're both updated I'm not sure it's worth the churn.

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

Looks like you've handled everything I can think of!

@oremanj oremanj merged commit e95aa05 into python-trio:master Nov 7, 2023
29 checks passed
@oremanj oremanj deleted the sniffio-via-tlocal branch November 7, 2023 00:45
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.

sniffio reports wrong current loop when used with trio_asyncio and trio 0.23
2 participants