nominatim.py: also catch deadlocks on final wait

This commit is contained in:
Sarah Hoffmann
2020-02-11 22:00:24 +01:00
parent 8b8aa1b4e6
commit 882f496e0a

View File

@@ -123,8 +123,20 @@ class DBConnection(object):
def wait(self): def wait(self):
""" Block until any pending operation is done. """ Block until any pending operation is done.
""" """
wait_select(self.conn) while True:
self.current_query = None try:
wait_select(self.conn)
self.current_query = None
return
except psycopg2.extensions.TransactionRollbackError as e:
if e.pgcode == '40P01':
log.info("Deadlock detected (params = {}), retry."
.format(self.current_params))
self.cursor.execute(self.current_query, self.current_params)
else:
raise
except psycopg2.errors.DeadlockDetected:
self.cursor.execute(self.current_query, self.current_params)
def perform(self, sql, args=None): def perform(self, sql, args=None):
""" Send SQL query to the server. Returns immediately without """ Send SQL query to the server. Returns immediately without
@@ -158,6 +170,8 @@ class DBConnection(object):
self.cursor.execute(self.current_query, self.current_params) self.cursor.execute(self.current_query, self.current_params)
else: else:
raise raise
except psycopg2.errors.DeadlockDetected:
self.cursor.execute(self.current_query, self.current_params)
return False return False