Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tornado + SQLAlchemy non-blocking DB calls

I'm relatively new to application development but here goes nothing.

I've been working on a project that employs the use of a Tornado server and SQLAlchemy's ORM for database management/access (using postgres in the back end).

At the outset of the project I hadn't considered the possibility that using SQLAlchemy would prevent me from taking advantage of Tornado's async features (since SQLAlchemy's database calls apparently 'block' the thread).

Do you have any suggestions as to how to implement an async-compatible setup with Tornado+SQLA+postgres?

like image 878
Mitch Avatar asked Feb 06 '26 20:02

Mitch


1 Answers

Take a look at aiopg - https://github.com/aio-libs/aiopg

It is a Python 3.4 asyncio adapter for postgres that includes sqlalchemy support. I haven't tried it myself yet, but found it while looking for async libraries for postgres and tornado. I am using Momoko, but it only supplies the raw psycopg2 layer.

Remember that the latest version of Tornado supports asyncio, so asyncio libraries will now work with Tornado.

like image 140
Michael Robellard Avatar answered Feb 12 '26 10:02

Michael Robellard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!