'Closes the current connection if unrecoverable errors have occurred,
or if it outlived its maximum age.'

def close_if_unusable_or_obsolete(self):

    if (self.connection is not None):
        if (self.get_autocommit() != self.settings_dict['AUTOCOMMIT']):
            self.close()
            return
        if self.errors_occurred:
            if self.is_usable():
                self.errors_occurred = False
            else:
                self.close()
                return
        if ((self.close_at is not None) and (time.time() >= self.close_at)):
            self.close()
            return
