code: def _ping_check(self, ping=1, reconnect=True):
          
          if ping & self._ping:
              try:  # if possible, ping the connection
                  alive = self._con.ping()
              except (AttributeError, IndexError, TypeError, ValueError):
                  self._ping = 0  # ping() is not available
                  alive = None
                  reconnect = False
              except Exception:
                  alive = False
              else:
                  if alive is None:
                      alive = True
                  if alive:
                      reconnect = False
              if reconnect and not self._transaction:
                  try:  # try to reopen the connection
                      con = self._create()
                  except Exception:
                      pass
                  else:
                      self._close()
                      self._store(con)
                      alive = True
              return alive
docs: Check whether the connection is still alive using ping().
  
          If the the underlying connection is not active and the ping
          parameter is set accordingly, the connection will be recreated
          unless the connection is currently inside a transaction.