Closed touilleMan closed 6 years ago
Whcih trio-asyncio version are you using? the current master should work better but needs test fixes and a release.
Before diving into the tricks required to make that work, I want to check– is it necessary? When I've seen this before it's been basically a clever hack to avoid writing async with await something()
, and IMO the extra confusion is not worth it, so normal trio style is to not support this.
@smurfix From what I see v0.7.5 on pypi and current master are on the same commit (c6c9c542645b5c3502ef3997677abe041f66454d). The bug is present in this version.
@njsmith that makes sense, I'll update the code to drop the broken await support then
support dropped by 721255251e9564789d75d4104dc13debaae3cf98
On second thought, there is a good reason connect
and create_pool
should be only available as async context managers: it's the only way for them to make sure they can teardown the asyncio part no matter what.
Otherwise we can end up in a strange situation when trio code has been cancelled but asyncio code is still running.
This also means pool.close
and connection.close
shouldn't be exposed by triopg because they are automatically called when leaving the async context manager.
(Well if Obi-Wan's not available, @njsmith and @smurfix could be of great help here ^^)
AsyncPG original API contains this
create_pool
(https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool) function that could be use both as an async function and as an async context manager.However this seems not to work in triopg due to weird interaction with trio-asyncio:
Here we endup with a Future object in the trio event loop. I've guess the way
__await__
is implemented (copied on what asyncpg does) doesn't get well with how trio-asyncio does it wrappinghttps://github.com/python-trio/triopg/blob/1899510e7aa3665d99fc9d544fff6c8a8cfa915a/triopg/_triopg.py#L103-L111