I often get this error:
ProgrammingError: The cursor's connection has been closed.
The wrapper is a good idea but I don't know any API to reliably check whether the connection is closed or not.
So the solution would be something along these lines:
for retry in range(3): try: ... execute query ... return # Stop on success except e: if is_connection_broken_error(e): reconnect() continue raise raise # throw if the retry fails too often