Catching accessdenied error for mac

This commit is contained in:
Caleb Herpin 2021-07-28 23:20:04 -05:00
parent bdca13d8e1
commit a6844fbeac

View File

@ -87,13 +87,18 @@ params = Params()
def is_web_server_started(port=params.get_port(), status_method="LISTEN"): def is_web_server_started(port=params.get_port(), status_method="LISTEN"):
isConnectionOpen = False isConnectionOpen = False
for _ in range(20): #Wait up to 2 seconds i.e 20 * .1 seconds, must wait for service to get to listening state. try:
for connection in psutil.net_connections(): for _ in range(20): #Wait up to 2 seconds i.e 20 * .1 seconds, must wait for service to get to listening state.
local_address = connection.laddr for connection in psutil.net_connections():
if len(local_address) > 1 and local_address[1] == port and connection.status == status_method: local_address = connection.laddr
isConnectionOpen = True if len(local_address) > 1 and local_address[1] == port and connection.status == status_method:
isConnectionOpen = True
break
if isConnectionOpen:
break break
if isConnectionOpen: sleep(.1) #We sleep to use less recourses
break except psutil.AccessDenied as e:
sleep(.1) #We sleep to use less recourses print("psutil.net_connections() requires root access on mac. Sleeping for 2 seconds instead.")
isConnectionOpen = True
sleep(2)
return isConnectionOpen return isConnectionOpen