Reputation: 3567
I have an InnoDB table which lists a bunch of files which need to be processed.
The python script which handles the processing basically does this:
This python script will be called multiple times, and so I am somewhat concerned that there could be some problem at step 1 and 2, where process B will get the same row from the db as process A before process A has the time to update the status in step 2.
I am guessing the Python GIL doesn't help me here since the interpreter will release the GIL when doing the SQL (right?). And from what I am reading, doing table locks on InnoDB doesn't work. Will the row-level locking take care of the issue here? If not, what are my other options?
Could I simply do "from threading import Lock" and add
with lock:
update_file_status(file_id, "processing")
?
Upvotes: 3
Views: 136
Reputation: 26729
use SELECT FOR UPDATE
statement - this will aquire exclusive lock on the row and won't allow other SELECT FOR UPDATE
on the same row.
Upvotes: 3