
Asyncio support for SQLAlchemy (and Flask, and any other blocking-IO library) - zzzeek
https://gist.github.com/zzzeek/2a8d94b03e46b8676a063a32f78140f1
======
aidos
I spotted this over the weekend, nice work zzzeek! The technical details still
evade me somewhat but it seems we can now run a big blob of synchronous code
with async around the edges. How deep are the changes required to sqlalchemy?
Do you just need to add some wrappers around going out to asyncpg?

EDIT I'm interested in this because the last time I looked, running sqla with
socketio looked like it wasn't going to be fun. Then my words were "if I can't
have sqla, then what's the point?" \- so we used Hasura to do the bulk of the
donkey work instead. Boy do I miss sqla when I'm in that part of the system
though.

~~~
zzzeek
the changes are so minimal it's almost embarrassing. basically none within
SQLAlchemy or anything else. you run in a greenlet and everything is normal.
when you get down to the driver, it's asyncpg, oh OK then we use await_().

if you look at
[https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2071](https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2071),
and scroll down, the Gerrit display shows you a listing of files. next to each
file is a bar that is a combination of green and red. Green means lines that
are added, red means lines that are removed. at the bottom, you can see the
total score, as of revision 13 it's 1581 lines added, 90 lines removed. That
is an insane ratio meaning literally nothing was changed, the vast majority of
the code is the new asyncpg dialect where I had to replicate the DBAPI and a
lot of other details that DBAPIs usually provide up front.

it's been several days now and it's looking more and more like the issue of
switching between asyncio and blocking style code is really easy to solve,
unless I'm in some kind of hallucinatory fugue state for the past three days
and all of these passing tests aren't really there.

