python - Should I use MySQL Lock Table or there exists better solution? -


I am working on a multi-processing application, and each process sometimes executes the following code:

Code> db_cursor.execute ("Select from MAX (id)" for record in pd

  

And I am facing the following problem: There can be a situation when two processes take the same maximum value, and both try to delete this value We do. Such a situation is not acceptable in the context of my application, each value should be taken only by one process (and removed)

How can I get it? Is there a good way to lock the table while taking the maximum maximum or delete it altogether or do it?

Thank you. Record with

GET_LOCK () ;

If you want to lock the lock, select the specific name for which you want to lock. Like 'prqueue_max_del' . Call SELECT GET_LOCK ('prqueue_max_del', 30) to lock the name to 'prqueue_max_del' . It will return 1 and set the lock if the name is available, or 0 if the lock is not available after 30 seconds (second parameter Timeout).

Use SELECT RELEASE_LOCK ('Prqueue_max_del') You will end up.

You must use the same name in each transaction and you must call GET_LOCK () in the transaction first set lock.

Beware; Since only the abstract name is closed, all other processes are not using this method and the abstract name, will be able to waste your table independently.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -