昨天我正在使用一些需要"选择...更新"概念的sqlalchemy东西来避免竞争条件.添加.with_lockmode('update')到查询对InnoDB和Postgres有效,但对于sqlite,我最终不得不潜入
if session.bind.name == 'sqlite':
session.execute('begin immediate transaction')
Run Code Online (Sandbox Code Playgroud)
在做选择之前.
这似乎现在有效,但感觉就像作弊.有一个更好的方法吗?