Skip to content

Conversation

pquentin
Copy link
Member

The main limitation is that sniffing isn't supported, as the way it's currently designed (starting a task in the background and never collecting it) is not compatible with structured concurrency.

The main limitation is that sniffing isn't supported, as the way it's currently designed (starting a task in the background and never collecting it) is not compatible with structured concurrency.
@pquentin pquentin changed the title Support Trio on httpx backend Support Trio with httpx Sep 23, 2025
)

async def sniff(self, is_initial_sniff: bool = False) -> None: # type: ignore[override]
if sniffio.current_async_library() != "asyncio":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more appropriate here to show the error when current_async_library == "trio", since we know for a fact that sniffing does not work with it? We don't know if sniffing works or not with other async libraries, I assume. And also, this function raises an exception when it cannot recognize which library is in use. For backwards compatibility maybe we should allow the sniffing in such a case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other async library?

  • I haven't seen https://github.com/dabeaz/curio used anywhere, and it isn't making new releases anyway.
  • Twisted isn't supported by sniffio or anyio
  • trio-asyncio never really took off, and switching to current_async_library == trio won't make any difference

I wouldn't see a different library making the same mistakes as asyncio, ie. allowing background tasks. Anyways, Trio has shown how hard it is for a different async library to take off, even with superior design, excellent docs, etc. So, for me, the condition makes sense: today, we only support sniffing with asyncio.

I find it interesting how this is exactly the discussion we're having in elastic/elasticsearch-py#3103 (comment).

return # Call at most once!

self._async_library = sniffio.current_async_library()
if self._async_library != "asyncio":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above here. This is unlikely, but let's say that someone using "curio" was able to make sniffing work before. This would prevent them from using this feature. I think the check should be for == "trio", which is the one case that we know fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, curio allows daemon tasks: https://curio.readthedocs.io/en/latest/reference.html#spawn. But I'm not aware of any HTTP client that supports curio. Since AnyIO dropped support for Curio, even asks does not support it. HTTPX does not support it.

"sniff_callback": sniff_callback,
}

print(kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this print intended or left over from a debug session?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, removed!

Copy link
Contributor

@miguelgrinberg miguelgrinberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I've noted that it is probably safe to check for trio to disable sniffing than to check for anything that is not asyncio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants