Skip to content

Commit

Permalink
Merge pull request #61 from Caltech-IPAC/FIREFLY-1528-macos-bug
Browse files Browse the repository at this point in the history
FIREFLY-1528: Fix FireflyClient failing to load sometimes on MacOS
  • Loading branch information
jaladh-singhal authored Aug 21, 2024
2 parents dcded94 + 6f1130a commit ede0e67
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions firefly_client/firefly_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,23 @@ def call_response(self, response):
warn('Response string:\n' + response.text[0:300])

raise err

@staticmethod
def _get_ip():
"""Find local IP address, based on https://stackoverflow.com/q/166506/8252556."""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('8.8.8.8', 1)) # doesn't even have to be reachable
ip = s.getsockname()[0]
except Exception:
ip = '127.0.0.1'
finally:
s.close()
return ip

def _is_page_connected(self):
"""Check if the page is connected.
"""
ip = socket.gethostbyname(socket.gethostname())
url = self.url_cmd_service + '?cmd=pushAliveCheck&ipAddress=%s' % ip
"""Check if the page is connected."""
url = f'{self.url_cmd_service}?cmd=pushAliveCheck&ipAddress={self._get_ip()}'
retval = self._send_url_as_get(url)
return retval['active']

Expand Down

0 comments on commit ede0e67

Please sign in to comment.