fix(sync): retry cleanup on Access -1102 lock contention
ACE ODBC reports lock contention ("无法更新;当前被锁定。(-1102)")
as a generic pyodbc.Error (HY000), NOT pyodbc.OperationalError, so the
old except clause never caught it and gave up after the first collision
— making cleanup_lock_retries:3 a no-op for the 氩弧焊/高写入库 -1102 case.
Now catch pyodbc.Error and retry only on lock messages ("被锁定"/"-1102"),
re-raising other errors immediately instead of retrying them 3×.
This commit is contained in:
@@ -111,8 +111,16 @@ class AccessReader:
|
|||||||
)
|
)
|
||||||
total += cur.rowcount
|
total += cur.rowcount
|
||||||
break
|
break
|
||||||
except pyodbc.OperationalError:
|
except pyodbc.Error as e:
|
||||||
if attempt < retries - 1:
|
# ACE ODBC reports lock contention ("无法更新;当前被锁定。
|
||||||
|
# (-1102)") as a generic ``pyodbc.Error`` (HY000), NOT as
|
||||||
|
# ``pyodbc.OperationalError`` — so the old handler silently
|
||||||
|
# missed it and gave up after the first collision. Retry only
|
||||||
|
# on lock messages; re-raise anything else so genuine errors
|
||||||
|
# surface immediately instead of being retried 3×.
|
||||||
|
msg = str(e)
|
||||||
|
is_lock = "被锁定" in msg or "-1102" in msg
|
||||||
|
if is_lock and attempt < retries - 1:
|
||||||
time.sleep(0.2 * (attempt + 1))
|
time.sleep(0.2 * (attempt + 1))
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user