[Async-sig] new library: sniffio – Sniff out which async library your code is running under

Nathaniel Smith njs at pobox.com
Sat Aug 18 17:13:18 EDT 2018


On Sat, Aug 18, 2018, 01:22 Chris Jerdonek <chris.jerdonek at gmail.com> wrote:

> Also, just to be clear, I think the idea of a library to sniff this
> information is great.
>
> It's just the location of where this information is being stored that
> I'm focusing in on and asking about. It seems like it should be in a
> "neutral" location, and in particular different from / decoupled from
> the library above.
>
> One advantage of decoupling the sniffing library from the registry
> location is that it would allow for someone to write an improved
> library in the future (say "detectio") without forever locking in /
> requiring the old library to be installed.


Yeah, we discussed this some when initially designing it, because we were
worried about the lock in issue too. Obviously if you want to do anything
you need to make some decisions, but to reduce the risk here we
intentionally kept sniffio as minimal and unopinionated as possible:
https://github.com/python-trio/sniffio/issues/1#issuecomment-408812146

Have you seen the code? It's not *entirely* trivial – certainly big enough
to contain a bug or two – but it's tiny and only contains what it
absolutely needs to work: a contextvar (native on 3.7, or via Yury's
backport library on earlier pythons), and a fallback for detecting asyncio
(since as a stdlib module it can't really work any other way).

https://github.com/python-trio/sniffio/blob/master/sniffio/_impl.py

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20180818/fe53ab81/attachment.html>


More information about the Async-sig mailing list