MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _run_with_retries

Method _run_with_retries

test/engine/test_reconnect.py:1565–1591  ·  view source on GitHub ↗
(fn, context, cursor, statement, *arg, **kw)

Source from the content-addressed store, hash-verified

1563 retry_interval = 0.5
1564
1565 def _run_with_retries(fn, context, cursor, statement, *arg, **kw):
1566 for retry in range(num_retries + 1):
1567 try:
1568 fn(cursor, statement, context=context, *arg)
1569 except engine.dialect.dbapi.Error as raw_dbapi_err:
1570 connection = context.root_connection
1571 if engine.dialect.is_disconnect(
1572 raw_dbapi_err, connection, cursor
1573 ):
1574 if retry > num_retries:
1575 raise
1576 engine.logger.error(
1577 "disconnection error, retrying operation",
1578 exc_info=True,
1579 )
1580 connection.invalidate()
1581
1582 connection.rollback()
1583
1584 time.sleep(retry_interval)
1585 context.cursor = cursor = (
1586 connection.connection.cursor()
1587 )
1588 else:
1589 raise
1590 else:
1591 return True
1592
1593 e = engine.execution_options(isolation_level="AUTOCOMMIT")
1594

Callers

nothing calls this directly

Calls 5

errorMethod · 0.80
is_disconnectMethod · 0.45
invalidateMethod · 0.45
rollbackMethod · 0.45
cursorMethod · 0.45

Tested by

no test coverage detected