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

sniffio reports wrong current loop when used with trio_asyncio and trio 0.23 #123

Closed
DaGenix opened this issue Nov 4, 2023 · 2 comments · Fixed by #124
Closed

sniffio reports wrong current loop when used with trio_asyncio and trio 0.23 #123

DaGenix opened this issue Nov 4, 2023 · 2 comments · Fixed by #124

Comments

@DaGenix
Copy link

DaGenix commented Nov 4, 2023

The following code works with Trio 0.22.2. However, it fails with 0.23.1:

import asyncio
import sniffio
import trio
from trio_asyncio import open_loop, aio_as_trio


@aio_as_trio
async def aio_func() -> None:
    await asyncio.sleep(1)  # The next line will fail. But, this sleep works fine which shows we are actually in asyncio context
    assert sniffio.current_async_library() == "asyncio"


async def main() -> None:
    assert sniffio.current_async_library() == "trio"
    async with open_loop():
        await aio_func()


if __name__ == "__main__":
    trio.run(main)
@A5rocks
Copy link
Contributor

A5rocks commented Nov 5, 2023

I'm going to guess this is because python-trio/trio#2700

I haven't checked to see if your sample works before then, but cc @oremanj just in case!


OK so failure bisects to that -- it looks like trio-asyncio uses current_async_library_cvar which unfortunately does not take precedence over the new thread_local mechanism.

@A5rocks
Copy link
Contributor

A5rocks commented Nov 5, 2023

OK I'm pretty sure this is a trio-asyncio issue so transferring this over to there.

@A5rocks A5rocks transferred this issue from python-trio/trio Nov 5, 2023
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 a pull request may close this issue.

2 participants