-
-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trio support. #811
Comments
I'm taking this up. |
@gdhameeja Can you share a link to your repo so we can follow along? |
Also, Edit: And |
I figured these possible alternatives / POC / intermediate steps are worth mentioning here. |
For what it's worth, here's an example of Uvicorn + Starlette + FastAPI running with trio-asyncio: python-trio/trio-asyncio#84 |
@gdhameeja any updates? I'd like to take a stab at using |
I took an initial stab at using It was surprisingly easy but I'd like some feedback if anyone would be so kind. |
Hi! Thanks for such an amazing work 🙌🏼 , I cannot wait to try |
@espetro For a very simple web server. In this I use hypercorn (runs the server) + starlette (handles the processing). 90% of Starlette worked on trio before the anyio patch. There were just a few bits (error handling is one I can think of) that failed / cashed. You really don't have to do anything to "enable" trio. Your web server (in my case hypercorn) is doing most of the heavy lifting. import trio
from hypercorn.config import Config
from hypercorn.trio import serve
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
class IPC(Starlette):
def __init__(self):
super().__init__(routes=[Route('/index', self._index)])
async def _index(self, request):
return JSONResponse({'foo': 'bar'}, status_code=200)
async def bootstrap():
hyper_config = Config.from_mapping({'bind': '127.0.0.1:56601'})
async with trio.open_nursery() as nursery:
nursery.start_soon(serve, IPC(), hyper_config)
if __name__ == '__main__':
trio.run(bootstrap) And then $ curl http://127.0.0.1:56601/index
{"foo":"bar"} |
Via https://gitter.im/python-trio/general?at=5e2fe9b940da694c5edc8d70
It'd be nice to have Starlette support both Trio and Asyncio.
Currently it's an asyncio-only framework, but there's actually not many places where we're tied to asyncio, with the exception of a bunch of "if this callable is a plain function then call into with with
run_in_threadpool
, otherwise await it.".I think the other places are:
.is_disconnected
- that I think is structured as an anti-pattern and probably needs rethinking.Short: Tweaking our run_in_threadpool function to use
sniffio
and then either call trio's threadpooling or asyncio's threadpooling would be sufficient as a starting point to start using Starlette with Trio.The text was updated successfully, but these errors were encountered: