- self.current_query = sql
- self.current_params = args
- self.cursor.execute(sql, args)
-
- def fileno(self):
- return self.conn.fileno()
-
- def is_done(self):
- if self.current_query is None:
- return True
-
- try:
- if self.conn.poll() == psycopg2.extensions.POLL_OK:
- self.current_query = None
- return True
- except psycopg2.extensions.TransactionRollbackError as e:
- if e.pgcode is None:
- raise RuntimeError("Postgres exception has no error code")
- if e.pgcode == '40P01':
- log.info("Deadlock detected, retry.")
- self.cursor.execute(self.current_query, self.current_params)
- else:
- raise
+ while True:
+ try:
+ self.cursor.execute(sql, args)
+ return
+ except psycopg2.extensions.TransactionRollbackError as e:
+ if e.pgcode is None:
+ raise RuntimeError("Postgres exception has no error code")
+ if e.pgcode == '40P01':
+ log.info("Deadlock detected, retry.")
+ else:
+ raise