From a6844fbeaca606de044347d9a8695beb47ddbaa1 Mon Sep 17 00:00:00 2001 From: Caleb Herpin Date: Wed, 28 Jul 2021 23:20:04 -0500 Subject: [PATCH] Catching accessdenied error for mac --- share/trick/pymods/trick/utils.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/share/trick/pymods/trick/utils.py b/share/trick/pymods/trick/utils.py index bef1376e..0fa45cca 100644 --- a/share/trick/pymods/trick/utils.py +++ b/share/trick/pymods/trick/utils.py @@ -87,13 +87,18 @@ params = Params() def is_web_server_started(port=params.get_port(), status_method="LISTEN"): 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. - for connection in psutil.net_connections(): - local_address = connection.laddr - if len(local_address) > 1 and local_address[1] == port and connection.status == status_method: - isConnectionOpen = True + try: + for _ in range(20): #Wait up to 2 seconds i.e 20 * .1 seconds, must wait for service to get to listening state. + for connection in psutil.net_connections(): + local_address = connection.laddr + if len(local_address) > 1 and local_address[1] == port and connection.status == status_method: + isConnectionOpen = True + break + if isConnectionOpen: break - if isConnectionOpen: - break - sleep(.1) #We sleep to use less recourses + sleep(.1) #We sleep to use less recourses + except psutil.AccessDenied as e: + print("psutil.net_connections() requires root access on mac. Sleeping for 2 seconds instead.") + isConnectionOpen = True + sleep(2) return isConnectionOpen