很抱歉問這個問題,但在搜索這個問題后我找不到任何有用的答案。我知道在 SQLAlchemy 的會話中,update()將無法工作,甚至可能無法與數(shù)據(jù)庫通信,直到您使用session.commit.這是我的代碼,我認為我使用的技能稱為optimistic lock:with Session() as session: # get one record object = session.query(Table).where(key=param).limit(1) content = "here is the calculated value of my business" # update the record by the id of the gotten record # if 2 thread get the same record and run into this update statement, I think only can success # because it is ensured by the MySQL MVCC Table.update(Table).set(Table.content = content).where(id = object.id) sessoin.commit()但是我在這里有一個問題,如果我想在in the thread which got the lock之后做點什么session.commit()?比如我期望的代碼是這樣的:affected_rows = sessoin.commit()if affected_rows: do_something_after_get_lock_success()有人可以幫忙嗎?非常感謝!^_^
添加回答
舉報
0/150
提交
取消