As discussed in agronholm/anyio#501 SniffIO doesn't detect it's running in asyncio when executing a callback added with loop.call_soon_threadsafe since it relies on asyncio.get_current_task for detection.
Using asyncio.get_running_loop should from my understanding work for all cases the current detection does and also allow detection in the case of executing in the event loop but not having a task.
I'll add a PR with the change implemented as well.