Experiment with trio support#342
Conversation
|
This is really cool! Thanks a lot! |
|
Yeah I’ll try to do it this week, thanks for the PR! |
|
I took a look at But trio doesn't have to be bound to riopg, right? triopg could be a better candidate I think, which is a wrapper of asyncpg. I'll try this route to see if everything works. |
|
In the spirit of explicitness, I prefer letting the user set current event loop (default to asyncio), but not using sniffio, which is a bit intrusive (adding ContextVar |
|
@wwwjfy Is riopg synchronous? (cc @Fuyukai). I thought that it uses psycopg2 in async mode: http://initd.org/psycopg/docs/advanced.html#asynchronous-support As implemented here: https://github.com/Fuyukai/riopg/blob/master/riopg/connection.py#L78 The reason I chose it, vs As for sniffio vs explicit setting the loop, I do not have a strong opinion. |
|
I didn't dig deep, but only tested I don't have too much problem with BTW, the simple script I used to test riopg. Ideally, import trio
import riopg
import multio
import psycopg2
multio.init('trio')
async def connect():
print(await riopg.Connection.open('postgresql://127.0.0.1:5433/postgres'))
async def a():
while True:
print('1')
await trio.sleep(1)
async def main():
async with trio.open_nursery() as nursery:
nursery.start_soon(connect)
nursery.start_soon(a)
trio.run(main) |
|
Plus, asyncpg has better support to PostgreSQL and better performance, at least it claims so. |
|
Hm, I always wondered why that function was never covered in riopg. Whoops! |
|
I can verify that But yes, I think to support anything based on |
|
Sorry for being dormant. Lately I've been thinking which one is a better solution, riopg or triopg. But yes you're right, it's really not my position to choose for users, as there is no obvious winner. |
|
@wwwjfy I am happy to help out where I can, or continue working on this pull request if you think it's the right direction. I also have a decent amount of experience with trio at this point, so if you have any questions regarding how to deal with the differences to asyncio, I might be able to help. |
|
Thanks! As for riopg, I want to spend time reading the code, to see if there is any issue. Not that I don't trust it, but since it's a relatively new project, with few users, there can be potential bugs. I want to have a better understanding on it (and its dependencies) before putting it as a dependency. As for prepared statements, looks like psycopg2 still hasn't supported that. So yes if we want to integrate psycopg2, we have to make it optional. |
|
Reading this again, I thought I was clear. Sorry about that. I think we can support as many backends as possible, and please go on with this PR. A few things I have in mind now:
|
684f7b1 to
3969c27
Compare
d3bba04 to
79e7d4c
Compare
I tried to make this run on top of the trio event loop. In a way, gino is uniquely positioned to support other event loops because it's dependency on
asynciois so light. It's basically just timeouts and one `asyncio.Lock. The rest is cleanly encapsulated within the dialect implementation.So this does two things:
riopg, which ispsycopg2on trio.At it stands, it runs the Showcase example successfully up until the last part where
gino.iterate()is used. I stumbled there because gino core uses prepared statements here, andpsycopg2does not support them. Or at least that was my impression.This is absolutely not merge-ready, but I did want to ask for some feedback, in particular if this is something that you see gino supporting.