Python app-level document/record locking (eg. for MongoDB)
The above code will fail with multiple worker nodes (or processes).
To achieve atomic find-and-update, mongodb provides native solution (findOneAndUpdate, findAndModify, updateOne, updateMany).