On 9/16/15 10:17 AM, Johnny W. Santos wrote:
Hi guys,
I would like to know if theres is any chances to SQLAlchemy support
asyncio out of the box? Like the ORM and such.
Well the "real" answer is "yes", which is that you'd put your ORM
business logic in a threadpool using
https://docs.python.org/3/library/asyncio-eventloop.html#executor. This
will by far get you the best separation of asyncio's ORM-unfriendly
concepts, the superior performance of traditional threads for that work,
and the programming patterns that some people find important in asyncio
on the outside of the traditional ORM-centric code. For rationale
on this as well as proof that asyncio's slowness and database
awkwardness is entirely not worth it nor even appropriate, see
http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/.
As far as an asyncio-explicit API for SQLAlchemy ORM, ORMs can't work
very well with asyncio because they rely upon "lazy loading", which is a
programming pattern directly in opposition to the philosophies of
asyncio. That said, the Core can be made to work in an asyncio fashion
but there's no roadmap for doing this extremely large amount of work
(issue is at
https://bitbucket.org/zzzeek/sqlalchemy/issues/3414/asyncio-and-sqlalchemy).
There's also a project that re-implements very partial versions of parts
of the Core to work on top of asynchronous psycopg2, that is
https://github.com/aio-libs/aiopg. Note however this project
re-implements the execution internals completely so basic features like
column defaults and datatypes won't really work as designed.
IMO there *is* a technically appropriate and performant solution to your
problem but it would require that you release any dogmatism you might
have over the use of traditional threaded code within the context of
explicit async code.
Thanks
Johnny
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.