It sure seems like the example code is just creating (with retries) a new connection for each SQL request. That should certainly work, but it seems like that could force a lot of unnecessary re-connections. I am assuming there is some overhead associated with creating a new connection and cursor.
By wrapping the cursor.execute() in a try/except and catching the pyodbc.OperationalError (and possibly test the error details) you could recreate the connection and cursor (and then retry the request) only when needed.
I also wonder if simply a simpler solution would be to keep track of how long the connection's been open and recreate it when it gets stale, similar to how it's done in example code for MS Graph connections.
OTOH, you cannot argue that catching all exceptions types (`except Exception as e:`) and retrying in 5 seconds will not solve a plethora of issues 🙂