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

implement sniffio using sys.get_asyncgen_hooks #27

Open
graingert opened this issue Aug 1, 2022 · 0 comments
Open

implement sniffio using sys.get_asyncgen_hooks #27

graingert opened this issue Aug 1, 2022 · 0 comments
Assignees

Comments

@graingert
Copy link
Member

graingert commented Aug 1, 2022

this works for trio curio and asyncio already. All twisted needs to do is implement set_asyncgen_hooks

def sniffio(_get_asyncgen_hooks=sys._get_asyncgen_hooks):
    hooks = _get_asyncgen_hooks()
    finalizer = hooks.finalizer
    if finalizer is not None:
        return finalizer.__module__.partition(".")[0]
    firstiter = hooks.firstiter
    if firstiter is not None:
        return firstiter.__module__.partition(".")[0]

trio-asyncio can twiddle with hooks.finalizer.__module__ to go back and forth between asyncio and trio

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

No branches or pull requests

2 participants