Is reading from database using sql alchemy threadsafe?

Is this the right pattern for reading from a sql database

I am not clear on how threading works. Will this still work if run in gunicorn with multiple threads.

elsewhere in forum there is a reference to flask_sqlalchemy (Update MySQL data in dash app) but I’m not clear if this is needed for query-only.


If you’re only querying, not writing anything, you shouldn’t need to worry about thread issues; two concurrent queries can’t interfere with each other. But if you do find a need for writing, flask_sqlalchemy does look like a good idea, they’ve taken some steps to make it more thread-safe than bare sqlalchemy by wrapping relevant calls in locks.

1 Like