Open
Description
I'm not sure whether this is a triopg
, quart_trio
, trio_asyncio
or a trio
issue. I'm trying to create and store a database connection using Quart's while_serving
handler like so:
from quart_trio import QuartTrio
import trio
import triopg
app = QuartTrio(__name__)
@app.while_serving
async def create_db():
async with triopg.connect("dbname=my_database user=my_user") as conn:
app.db = conn
yield
app.run()
However this is resulting in the following error:
Running on http://127.0.0.1:5000 (CTRL + C to quit)
[2021-09-18 19:22:48,223] Running on http://127.0.0.1:5000 (CTRL + C to quit)
Traceback (most recent call last):
File "<snip>/.venv/lib/python3.9/site-packages/quart_trio/asgi.py", line 117, in __call__
await self.app.startup()
File "<snip>/.venv/lib/python3.9/site-packages/quart/app.py", line 1757, in startup
await gen.__anext__()
File "<snip>/main.py", line 11, in create_db
async with triopg.connect("dbname=my_database user=my_user") as conn:
File "<snip>/.venv/lib/python3.9/site-packages/triopg/_triopg.py", line 195, in __aenter__
self._asyncpg_conn = await trio_asyncio.aio_as_trio(
File "<snip>/.venv/lib/python3.9/site-packages/trio_asyncio/_adapter.py", line 54, in __call__
return await self.loop.run_aio_coroutine(f)
AttributeError: 'NoneType' object has no attribute 'run_aio_coroutine'
I did find this comment, however it doesn't quite seem relavent here python-trio/trio-asyncio#110 (comment)
It could be that I'm mis-using these libraries, in which case it would be awesome if someone could point me in the right direction. Currently I'm creating a single connection for the entire app, however in practice I'd like to use the connection pool in a similar way.
Metadata
Metadata
Assignees
Labels
No labels