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

2018-08-21 Thread Nathaniel Smith
On Sat, Aug 18, 2018 at 2:44 PM, Chris Jerdonek wrote: > The kind of alternative I had in mind for a neutral location is > setting an attribute with an agreed upon name on a module in the > standard lib, perhaps something like > `contextvars.current_async_library_cvar` to use your naming. This is

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

2018-08-18 Thread Chris Jerdonek
On Sat, Aug 18, 2018 at 2:13 PM, Nathaniel Smith wrote: > On Sat, Aug 18, 2018, 01:22 Chris Jerdonek 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

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

2018-08-18 Thread Nathaniel Smith
On Fri, Aug 17, 2018 at 11:44 PM, Chris Jerdonek wrote: > On Fri, Aug 17, 2018 at 12:50 PM, Nathaniel Smith wrote: >> On Fri, Aug 17, 2018, 12:12 Chris Jerdonek wrote: >>> >>> Did you also think about whether it would be possible for a library to >>> advertise itself without having to depend on

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

2018-08-18 Thread Chris Jerdonek
On Fri, Aug 17, 2018 at 12:50 PM, Nathaniel Smith wrote: > On Fri, Aug 17, 2018, 12:12 Chris Jerdonek wrote: >> >> Did you also think about whether it would be possible for a library to >> advertise itself without having to depend on a third-party library >> (e.g. using some sort of convention)?

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

2018-08-17 Thread Nathaniel Smith
On Fri, Aug 17, 2018, 09:09 Alex Grönholm wrote: > This was my approach: > > def _detect_running_asynclib() -> str: > if 'trio' in sys.modules: > from trio.hazmat import current_trio_token > try: > current_trio_token() > except RuntimeError: >

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

2018-08-17 Thread Chris Jerdonek
If I'm reading the docs correctly, it looks like an async library has to depend on sniffio in order to be detected by sniffio: https://sniffio.readthedocs.io/en/latest/#adding-support-to-a-new-async-library Did you also think about whether it would be possible for a library to advertise itself

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

2018-08-17 Thread Alex Grönholm
If you look at the code more carefully, you'll see that I'm not merely checking what's been imported. In each case I'm asking the relevant framework if they're running an event loop *in the current thread*. pe, 2018-08-17 kello 09:26 -0700, Brett Cannon kirjoitti: > Importation does not equate to

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

2018-08-17 Thread Brett Cannon
Importation does not equate to execution. I.e. since I could have multiple event loops running at once that means what's in sys.modules can't tell me what event loop I'm currently interacting with. On Fri, 17 Aug 2018 at 09:09 Alex Grönholm wrote: > This was my approach: > > def

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

2018-08-17 Thread Alex Grönholm
This was my approach: def _detect_running_asynclib() -> str: if 'trio' in sys.modules: from trio.hazmat import current_trio_token try: current_trio_token() except RuntimeError: pass else: return 'trio' if 'curio' in

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

2018-08-16 Thread Guido van Rossum
Neat! On Thu, Aug 16, 2018 at 9:02 AM Nathaniel Smith wrote: > Hi all, > > A number of people are working on packages that support multiple async > backends (e.g., asyncio + trio, or trio + curio, or trio + twisted, > ...). So then the question arises... how can I figure out which async >

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

2018-08-16 Thread Nathaniel Smith
Hi all, A number of people are working on packages that support multiple async backends (e.g., asyncio + trio, or trio + curio, or trio + twisted, ...). So then the question arises... how can I figure out which async library my user is actually using? Answer: install sniffio, and then call