Support for trio via anyio #1932
Replies: 6 comments 3 replies
-
Hi @graingert ! However, there are some concerns we'd probably need to address before moving forward.
Generally speaking, we're more flexible when it comes to the test suite, so most of the above concerns do not apply there. Looking at https://github.com/encode/starlette/pull/1157/files, it doesn't look too heavy, particularly given that Falcon doesn't do certain types of wrapping automagic, adapters and built-in servers found in Starlette, however, it would still be good to get a feeling how big the required changes are. Maybe you could start from a limited MVP prototype, or even just a quick review what needs to be done in the codebase, just to prove feasibility; and we could take it from there? |
Beta Was this translation helpful? Give feedback.
-
I like the idea of doing some initial prototyping. Providing 100% test coverage for the ASGI paths can actually be more challenging vs. writing the implementation, so I would be interested in seeing how many additional paths anyio support would require (in addition to running our existing test suite against a trio-enabled Falcon app). I would also be interested in seeing if there are any strange edge cases that trio's behavior brings up that we would have to handle and test. If the changes are minimal, the edge cases few, and the dependencies are unlikely to see a lot of churn (i.e., the anyio/trio interfaces are stable) we can probably absorb the maintenance burden, esp. if we get some help. 😉 Also, echoing @vytas7, we would need to avoid introducing any significant performance degradations. And we would also need to avoid introducing a required dependency to Falcon, since having zero dependencies is indeed important to a segment of our community. In other words, we would need to make it possible to swap anyio/trio for asyncio without requiring any dependencies for a default Falcon installation. And again, doing so without introducing a performance regression. |
Beta Was this translation helpful? Give feedback.
-
Re dependencies, another point to consider is that the majority of Falcon users are likely still on WSGI, at least when it comes to existing code bases. For them, On the positive side, our direct usage of |
Beta Was this translation helpful? Give feedback.
-
I hope I'm not already sounding as a big naysayer, as I also love the ideas behind Trio! |
Beta Was this translation helpful? Give feedback.
-
Unfortunately this might get delayed even more on our side, as it seems Uvicorn has closed the respective issues both for HTTP/2 and Trio without fixing them. So unless there exists a performant, production ready ASGI server with Trio support, it will be hard for us to find motivation and time to invest into this. A community PR might still be considered though. |
Beta Was this translation helpful? Give feedback.
-
Hi again @graingert! I was trying to estimate the amount of work needed to make this happen, and it doesn't seem too complicated as Falcon doesn't make too heavy use of However, there are some complications where I'm not sure what the best design is, for instance, one can schedule tasks via Should I construct an async def fancy_task(task_status=anyio.TASK_STATUS_IGNORED):
task_status.started()
await anyio.sleep(1.0)
logging.info('Exiting fancy_task...')
async def scheduled_task(message):
await anyio.sleep(3.0)
logging.info(f'Scheduled task: {message=}')
async def main():
# Earlier in the application, e.g., in ASGI lifespan handler
stack = contextlib.AsyncExitStack()
bg_tg = await stack.enter_async_context(anyio.create_task_group())
async with anyio.create_task_group() as tg:
logging.info('Pretending to handle request...')
await tg.start(fancy_task)
logging.info('Scheduling task...')
bg_tg.start_soon(scheduled_task, 'Hello, World! #1')
bg_tg.start_soon(scheduled_task, 'Hello, World! #2')
async with anyio.create_task_group() as tg:
logging.info('Pretending to handle another request...')
await tg.start(fancy_task)
await tg.start(fancy_task)
logging.info('Scheduling other tasks...')
bg_tg.start_soon(scheduled_task, 'Task #2')
# ASGI Lifespan shutdown event could attempt this
await stack.aclose() (Seems to work? 🤔) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Starlette has recently added support for trio via anyio
And I'm interested in using falcon on trio too, and would be happy to help with a port to anyio
Beta Was this translation helpful? Give feedback.
All reactions