python - Getting 'Deadlock found when trying to get lock; try restarting transaction' -


I have a multi-processing application, and each thread executes the following Python code:

 While true: db_cursor.execute ("set autocommit = 0;") db_cursor.execute ("type lock tabs prqueue;") db_cursor.execute ("select from max (id) prqueue;") db_cursor.fetchall ( ) To record: if the record [0]: db_cursor.execute ("Removed from WHERE id = '% s';"% record [0]); # Db_connector.commit () db_cursor.execute ("COMMIT,") db_cursor.execute ("unlock tables";) # There is some work that takes more time: db_cursor.execute ("COMMIT,") db_cursor.execute ("Tables Unlock; ")  

Occasionally my processes die with the operation exception: found deadlock while trying to get a lock; Try to start the transaction again '.

And the most odd thing is that the processes die on different lines. For example, error messages from 3 of them:

  traceback (most recent call final): file "/usr/lib/python2.7/multiprocessing/process.py", line 258. In the _bootstrap self.run () file "/usr/lib/python2.7/multiprocessing/process.py", line 114, run self._target (* self._args, ** self._kwargs) file "/ Home / crawler /Worker.py ", line 122, do_crawling in db_cursor.execute (" COMMIT, ") file" /usr/lib/python2.7/dist-packages/MySQLdb/cursors.py ", line 174, in self .handhandler executed (self, exc, value) file "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in the defaulterrorhandler raise error class, errorwidth OperationalE Rror: (1213, 'Lock deadlock while trying to get', try to restart the transaction) Traceback (most recent call final): File "/usr/lib/python2.7/multiprocessing/process. Py ", line 258," / usr / lib / Python2.7 / multiprocessing / process.py "in the _bootstrap self.run () file, line 114, self._target (* self._args, ** self. _kwargs) file "/home/crawler/Worker.py", line 122, in db_cursor.execute do_crawling ("COMMIT,") file "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", In line 174, execute the file on self.errorhandler (self, exc, value) "/usr/lib/python2.7/dist-packages/MySQLdb/connect Ions.py ", line 36 defaulterrorhandler in the errorclass, errorvalue OperationalError: (1213; found deadlock while trying to get 'lock; Traceback (try restarting) traceback (most recent call final): "/usr/lib/python2.7/multiprocessing/process.py" in the file, line 258, _bootstrap self.run () file "/ Usr / lib / python2.7 / multi-processing / process.py ", line 114, run itself. _ Target (* self._args, ** self._kwargs) file "/home/crawler/Worker.py", line 109, in do_crawling db_cursor.execute (file "/ url / lib / python2.7 / dist-packages / MySQLdb / cursors.py ", line 174, to execute itself.Terrorist (self, exc, value) file" /usr/lib/python2.7/dist-packages/MySQLdb/connections.py ", line 36, Defaulterrorhandler in the errorclass, errorvalue OperationalError: (1213, 'try to get lock when found deadlock, restart transaction')  

Am I doing something wrong in this code

Thank you.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -