def kill_connection(self): try: self.Con.kill(self.Con.thread_id()) except (pymysql.OperationalError, pymysql.InternalError): pass