import sqlite3 # Setup: create an in-memory DB with some orders conn = sqlite3.connect(":memory:") conn.execute("CREATE TABLE orders (order_id, customer_id, amount, status)") conn.executemany("INSERT INTO orders VALUES (?, ?, ?, ?)", [ (1, 101, 59.99, "completed"), (2, 102, 120.00, "completed"), (3, 101, 34.50, "refunded"), (4, 103, 89.00, "completed"), ]) conn.commit() # Simulate a connection that fails twice before succeeding attempt_count = 0 @retry(max_attempts=3, delay=1, exceptions=(sqlite3.OperationalError,)) def fetch_completed_orders(conn): global attempt_count attempt_count += 1 if attempt_count < 3: raise sqlite3.OperationalError("database is locked") cursor = conn.execute("SELECT * FROM orders WHERE status = 'completed'") return cursor.fetchall() rows = fetch_completed_orders(conn) print(rows)