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. :-)
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.
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.
SQLAlchemy supports MySQL starting with version 5.0. 2 through modern releases, as well as all modern versions of MariaDB.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With