Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use SQLalchemy with gevent?

I know that some database drivers and other libraries providing connection to external services are incompatible with coroutine-based network libraries. However, I couldn't find out if SQLAlchemy can be safely used with such libraries (namely, gevent), and if any workarounds should be applied to exclude possible errors.

Can you either tell me that or point me to an article where I can read this information? An additional 'thank you' if the provided answer also contains explanation of the mechanics of why it is okay or why it isn't. :-)

like image 644
dpq Avatar asked Oct 27 '10 13:10

dpq


People also ask

Is SQLAlchemy engine thread safe?

Every pool implementation in SQLAlchemy is thread safe, including the default QueuePool . This means that 2 threads requesting a connection simultaneously will checkout 2 different connections. By extension, an engine will also be thread-safe.

Is SQLAlchemy worth using?

SQLAlchemy is the ORM of choice for working with relational databases in python. The reason why SQLAlchemy is so popular is because it is very simple to implement, helps you develop your code quicker and doesn't require knowledge of SQL to get started.

Can I use SQLAlchemy with MySQL?

SQLAlchemy supports MySQL starting with version 5.0. 2 through modern releases, as well as all modern versions of MariaDB.

Is SQLAlchemy blocking?

Short answer, no. It's the database libraries that are blocking, not SQLalchemy itself. Nothing stops you from doing DB stuff in a separate thread, though.


1 Answers

Did you try searching gevent google group for SQLAlchemy?

I found this report of using SQLAlchemy + mysql-connector successfully and this of using SQLAlchemy + psycopg2 successfully (make sure you've read this)

I would think SQLAlchemy should be safe to use with gevent as long as the database driver that SQLAlchemy uses is safe, but I've not tried it myself and only basing this on the reports from other users.

like image 87
Denis Avatar answered Oct 18 '22 05:10

Denis