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