Flask-SQLAlchemy with_for_update() row lock
问题 I have a model called 'User', and 'User' has 'Money'. There a scenario that multiple session can read the model 'User' and update 'money' at the same time. Session 2 should read the 'money' value after session 1 updated successfully. I tried to lock the 'User' row when updating. Here's my code. user = User.query.with_for_update().filter_by(id=userid).first() print('000000') before_money = user.money print('111111') time.sleep(1) user.money -= 0.1 print('User:' + str(user.id) + '***' + str