![](https://secure.gravatar.com/avatar/97c543aca1ac7bbcfb5279d0300c8330.jpg?s=120&d=mm&r=g)
On Fri, Aug 17, 2018, 09:09 Alex Grönholm <alex.gronholm@nextday.fi> 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: pass else: return 'trio'
if 'curio' in sys.modules: from curio.meta import curio_running if curio_running(): return 'curio'
if 'asyncio' in sys.modules: from .backends.asyncio import get_running_loop if get_running_loop() is not None: return 'asyncio'
raise LookupError('Cannot find any running async event loop')
Is there something wrong with this?
If you're using trio-asyncio, then you can have both trio-flavored coroutines and asyncio-flavored coroutines running in the same thread. And in particular, the trio and asyncio tests you do above will both return true at the same time, even though at any given moment only you can only 'await' one kind of async function or the other. Twisted running on the asyncio reactor has a similar situation. -n