Open SamP20 opened 3 years ago
I just got this error and was able to fix it by starting the main task using trio_asyncio.run
as the readme example shows instead of trio.run
. Makes sense to me because the library wraps the asyncio
library asyncpg
. Not familiar with Quart, but my guess is the solution in this case is to find some way for Quart to start its main task using trio_asyncio
.
@SamP20 as @jakobcornell says, trio_asyncio can lead to tricky lifetime issues: typically you may have a coroutine creating the trio_asyncio scope, and a coroutine from a parent scope (typically what is done with @app.while_serving
) that uses the component needing trio_asyncio. Then when the coroutine with the trio_asyncio scope stops things get messy 😄
So the best strategy it to try to have trio_asyncio scope as high as possible (and if possible uses trio_asyncio.run
instead of trio.run
!)
I'm not sure whether this is a
triopg
,quart_trio
,trio_asyncio
or atrio
issue. I'm trying to create and store a database connection using Quart'swhile_serving
handler like so:However this is resulting in the following error:
I did find this comment, however it doesn't quite seem relavent here https://github.com/python-trio/trio-asyncio/issues/110#issuecomment-769983648
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.