Are transactions in SQLAlchemy thread safe?

前端 未结 2 1918
予麋鹿
予麋鹿 2021-01-06 08:39

I am developing a web app using SQLAlchemy\'s expression language, not its orm. I want to use multiple threads in my app, but I\'m not sure about thread safety. I am using

2条回答
  •  佛祖请我去吃肉
    2021-01-06 09:10

    I think you are confusing atomicity with isolation.

    Atomicity is usually handled through transactions and concerns integrity.

    Isolation is about concurrent read/write to a database table (thus thread safety). For example: if you want to increment an int field of a table's record, you will have to select the record's field, increment the value and update it. If multiple threads are doing this concurrently the result will depend on the order of the reads/writes.

    http://docs.sqlalchemy.org/en/latest/core/engines.html?highlight=isolation#engine-creation-api

提交回复
热议问题