Compatability with trio (alt async lib) #3451
Replies: 2 comments 5 replies
-
There is a wiki entry dedicated just for this: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Frequently-requested-design-patterns#running-ptb-alongside-other-asyncio-frameworks Hope it helps :) |
Beta Was this translation helpful? Give feedback.
-
Hi. Thanks for reaching out. TBH I've never worked with trio before and I'm not really familiar with the differences between trio and asyncio. So let me start with a more general note: PTB tries rather hard to be as dependency-free as possible. Currently the only required 3rd party dependency is Adding a 3rd party dependency for the concurrency logic would systematically be rather different, as we use the concurrency basically throughouth the whole library. If one would decide to make this dependency an optional depndency as well, this would e.g. mean that we have to run the whole test-suite twice. Now a bit more in the direction of trio/effort to reimplement. I dare say that PTB does not use much of hacky lowlevel asyncio stuff. I searched through our lib and the functionality that we use currently is: asyncio.{
loop.{
AFAIK, managing tasks is handled somewhat different in trio, where they use the nurseries. IIRC a similar concept has also been introduced in py3.10/3.11. For the @brandyn if you gain more insights on this, please let us know. If one aims for supporting trio, I personally see two options in terms of dependencies:
So far, this thread is the first request for support of a non-asyncio library (next to trio, there's also curio and twisted, both not supported by anyio). As the effort to support trio is probably not trivial, I'm not overly enthusiastic to get started right away, tbh. I would suggest that we handle this simlarly to #3355 for now, i.e. we open a feature-request issue that's not on any roadmap and wait to see if there's a critical mass of users who would like to have this feature. If there is, we can still discuss how we want to handle the additional dependencies. Let me cc the other dev-team members to see if they have additional comments: |
Beta Was this translation helpful? Give feedback.
-
Is there any interest in making this compatible with trio (https://trio.readthedocs.io/en/stable/)?
I find trio vastly cleaner than the default async libs, and my entire home-automation system is built on it.
I'm not sure how hard it is to make something compatible with both, but I've seen projects do it.
I currently use python-telegram-bot in trio via a background thread wrapper (ick, but it works). I haven't tried to use the async version (somewhat worried that, ironically, due to the upgrade to async, it will no longer work for me even though I've been using it async for years..).
Beta Was this translation helpful? Give feedback.
All reactions