def auto_reconnect_cursor(func):
 @wraps(func)
 def inner(self, *args, **kwargs):
  try:
   return func(self, *args, **kwargs)
  except Exception as e:
   if (not can_reconnect(e)):
    raise
   self.db.close(reconnect=True)
   self.cursor = self.db._cursor()
   return func(self, *args, **kwargs)
 return inner

def auto_reconnect_cursor ( func ) : @ wraps ( func ) def inner ( self , * args , ** kwargs ) : try : return func ( self , * args , ** kwargs ) except Exception as e : if ( not can_reconnect ( e ) ) : raise self . db . close ( reconnect = True ) self . cursor = self . db . _cursor ( ) return func ( self , * args , ** kwargs ) return inner
attempt to safely reconnect when an error is hit that resembles the bouncer disconnecting the client due to a timeout/etc during a cursor execution .