I have a function in sqlalchemy (python3) that I first select from a table and then update those selected rows. I want to lock these two executions so that if my function is triggered multiple times at the same time, the execution should be in a queue and not concurrently becasue this will produce unexpected results. I am having trouble understanding how to implement this. Any help is appreciated.
def myfunction():
qry = db.session.query(MyTable).filter(MyTable.is_set==False).limit(4).all()
for row in qry:
row.is_set = True
db.session.commit()
This function might be called at the same time, and if I don't use a lock mechanism it would generate unexpected results.
So I want to make sure execution of this function would be one after the other instead of being concurrently