Commit 0d36de7b authored by Julien Muchembled's avatar 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.
parent b0023b43
...@@ -124,18 +124,19 @@ class NEOLogger(Logger): ...@@ -124,18 +124,19 @@ class NEOLogger(Logger):
def commit(self): def commit(self):
try: try:
self._db.commit() self._db.commit()
except sqlite3.OperationalError, e: except sqlite3.OperationalError as e:
x = e.args[0] x = e.args[0]
if x == 'database is locked': if x != 'database is locked':
raise
sys.stderr.write('%s: retrying to emit log...' % x) sys.stderr.write('%s: retrying to emit log...' % x)
while e.args[0] == x: while 1:
try: try:
self._db.commit() self._db.commit()
except sqlite3.OperationalError, e: break
continue except sqlite3.OperationalError as e:
sys.stderr.write(' ok\n') if e.args[0] != x:
return
raise raise
sys.stderr.write(' ok\n')
def backlog(self, max_size=1<<24, max_packet=None): def backlog(self, max_size=1<<24, max_packet=None):
with self: with self:
......
...@@ -42,17 +42,18 @@ def unique_constraint_message(table, *columns): ...@@ -42,17 +42,18 @@ def unique_constraint_message(table, *columns):
def retry_if_locked(f, *args): def retry_if_locked(f, *args):
try: try:
return f(*args) return f(*args)
except sqlite3.OperationalError, e: except sqlite3.OperationalError as e:
x = e.args[0] x = e.args[0]
if x == 'database is locked': if x != 'database is locked':
raise
msg = traceback.format_exception_only(type(e), e) msg = traceback.format_exception_only(type(e), e)
msg += traceback.format_stack() msg += traceback.format_stack()
logging.warning(''.join(msg)) logging.warning(''.join(msg))
while e.args[0] == x: while 1:
try: try:
return f(*args) return f(*args)
except sqlite3.OperationalError, e: except sqlite3.OperationalError as e:
pass if e.args[0] != x:
raise raise
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment