Optimized some ancient code in the debug client backend. eric7

Sun, 13 Feb 2022 15:00:25 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 13 Feb 2022 15:00:25 +0100
branch
eric7
changeset 8947
579e286300d1
parent 8946
0ca4f57f15b6
child 8948
9ddea4f0ad87

Optimized some ancient code in the debug client backend.

eric7/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
--- a/eric7/DebugClients/Python/DebugClientBase.py	Sat Feb 12 23:05:25 2022 +0100
+++ b/eric7/DebugClients/Python/DebugClientBase.py	Sun Feb 13 15:00:25 2022 +0100
@@ -7,21 +7,20 @@
 Module implementing a debug client base class.
 """
 
-import sys
-import socket
-import select
+import atexit
+import codecs
 import codeop
-import codecs
-import traceback
-import os
+import contextlib
+import fnmatch
 import json
+import os
 import re
-import atexit
+import select
 import signal
-import time
+import socket
+import sys
+import traceback
 import types
-import fnmatch
-import contextlib
 
 import DebugClientCapabilities
 import DebugVariables
@@ -2047,21 +2046,18 @@
             host, version = host.split("@@")
         except ValueError:
             version = 'v4'
-        family = socket.AF_INET if version == 'v4' else socket.AF_INET6
         
-        retryCount = 0
-        while retryCount < 20:
-            try:
-                addrinfo = socket.getaddrinfo(
-                    host, None, family, socket.SOCK_STREAM)
-                return addrinfo[0][4][0]
-            except Exception:
-                retryCount += 1
-                family = (socket.AF_INET if family == socket.AF_INET6 else
-                    socket.AF_INET6
-                )
-                if retryCount % 2 == 0:
-                    time.sleep(3)
+        family = (
+            0
+            if version.startswith("i") else
+            (socket.AF_INET if version == 'v4' else socket.AF_INET6)
+        )
+        
+        with contextlib.suppress(OSError):
+            addrinfo = socket.getaddrinfo(
+                host, None, family, socket.SOCK_STREAM)
+            return addrinfo[0][4][0]
+        
         return None
     
     def main(self):

eric ide

mercurial