Skip to content

implement sniffio using sys.get_asyncgen_hooks #27

@graingert

Description

@graingert

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions