without sudo, psutil.net_connections() raises psutil.AccessDenied on mac; in this case, silently try running chrome on the unvetted configured port

This commit is contained in:
Noah Levitt 2016-05-09 17:25:14 -07:00
parent 1141c5951e
commit 317a5eb99d

View File

@ -157,9 +157,14 @@ class Browser:
port_available = False port_available = False
port = self.chrome_port port = self.chrome_port
for p in range(port,65535): try:
if any(connection.laddr[1] == p for connection in psutil.net_connections(kind='tcp')): conns = psutil.net_connections(kind="tcp")
self.logger.warn("Port already open %s, will try %s", p, p + 1) except psutil.AccessDenied:
return port
for p in range(port, 65535):
if any(connection.laddr[1] == p for connection in conns):
self.logger.warn("port %s already open, will try %s", p, p+1)
else: else:
port = p port = p
break break