From f129f99faa204e9453a1882045ac82b366b26599 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 15 Sep 2021 21:01:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=8E=B7=E5=8F=96Hostname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/startup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/terminal/startup.py b/apps/terminal/startup.py index f2d8d64e7..7c3fffe69 100644 --- a/apps/terminal/startup.py +++ b/apps/terminal/startup.py @@ -23,9 +23,16 @@ class BaseTerminal(object): name = f'[{suffix_name}]-{hostname}' self.name = name self.interval = 30 - self.remote_addr = socket.gethostbyname(hostname) + self.remote_addr = self.get_remote_addr(hostname) self.type = _type + @staticmethod + def get_remote_addr(hostname): + try: + return socket.gethostbyname(hostname) + except socket.gaierror: + return '127.0.0.1' + def start_heartbeat_thread(self): print(f'- Start heartbeat thread => ({self.name})') t = threading.Thread(target=self.start_heartbeat)