我在MySQL数据库表中包含“任务”。每个任务都有标志(不管是否接受)。
现在,例如,3个线程做:
query_base = session.query(PredykcjaRow).filter(
PredykcjaRow.predyktor == predictor,
PredykcjaRow.czy_wziete == False
)
query_disprot = query_base.join(NieustrRow, NieustrRow.fastaId == PredykcjaRow.fastaId)
query_pdb = query_base.join(RawBialkoRow, RawBialkoRow.fasta_id == PredykcjaRow.fastaId)
response = query_pdb.union(query_disprot)
response = response.with_for_update()
response = response.first()
if response is None:
return None
response.czy_wziete = True
try:
session.commit()
return response
except:
return None每个线程都有自己的会话(ScopedSession),但所有3个线程都有相同的对象。
在配置中
tx_isolation..... REPEATABLE-READ发布于 2016-08-20 23:41:16
问题是工会声明。MySQL不提供用于UPDATE的累积选择-它在没有警告的情况下执行,但是行没有被锁定。
我在官方文件中找到了这个信息,但现在我做不到。如果有人可以,请发表评论。
发布于 2016-08-06 23:10:35
假设创建了范围会话,如下所示:
Session = scoped_session(sessionmaker(bind=engine))确保你没有这样做
session = Session()
give_to_thread1(session)
give_to_thread2(session)对于限定作用域的会话,您可以直接使用它。
Session.query(...)因此,您的线程应该这样做:
def runs_in_thread():
Session.add(...)
# or
session = Session()
session.add(...)https://stackoverflow.com/questions/38809288
复制相似问题