Commit 0d36de7b by Julien Muchembled

Fix 2 'except' statements that will bug when moving to Python 3

Previous code relied on the fact that the exception target is kept past
the end of the except clause. 2to3 is not smart enough to detect that.

Without this change, a different OperationalError exception would be
ignored because there's already a local variable of the same name.
1 parent b0023b43
......@@ -124,18 +124,19 @@ class NEOLogger(Logger):
def commit(self):
try:
self._db.commit()
except sqlite3.OperationalError, e:
except sqlite3.OperationalError as e:
x = e.args[0]
if x == 'database is locked':
sys.stderr.write('%s: retrying to emit log...' % x)
while e.args[0] == x:
try:
self._db.commit()
except sqlite3.OperationalError, e:
continue
sys.stderr.write(' ok\n')
return
raise
if x != 'database is locked':
raise
sys.stderr.write('%s: retrying to emit log...' % x)
while 1:
try:
self._db.commit()
break
except sqlite3.OperationalError as e:
if e.args[0] != x:
raise
sys.stderr.write(' ok\n')
def backlog(self, max_size=1<<24, max_packet=None):
with self:
......
......@@ -42,18 +42,19 @@ def unique_constraint_message(table, *columns):
def retry_if_locked(f, *args):
try:
return f(*args)
except sqlite3.OperationalError, e:
except sqlite3.OperationalError as e:
x = e.args[0]
if x == 'database is locked':
msg = traceback.format_exception_only(type(e), e)
msg += traceback.format_stack()
logging.warning(''.join(msg))
while e.args[0] == x:
try:
return f(*args)
except sqlite3.OperationalError, e:
pass
raise
if x != 'database is locked':
raise
msg = traceback.format_exception_only(type(e), e)
msg += traceback.format_stack()
logging.warning(''.join(msg))
while 1:
try:
return f(*args)
except sqlite3.OperationalError as e:
if e.args[0] != x:
raise
class SQLiteDatabaseManager(DatabaseManager):
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!