Skip to content

Commit

Permalink
Confirm that the connection to tensorboard works or change to localho…
Browse files Browse the repository at this point in the history
…st (#2371)
  • Loading branch information
mm3509 authored Mar 13, 2020
1 parent 3da17e6 commit 9465b89
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions tensorboard/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ def __init__(self, wsgi_app, flags):
host = "localhost"

self._host = host
self._url = None # Will be set by get_url() below

self._fix_werkzeug_logging()
try:
Expand Down Expand Up @@ -727,20 +728,30 @@ def handle_error(self, request, client_address):
logger.error("HTTP serving error", exc_info=exc_info)

def get_url(self):
if self._auto_wildcard:
display_host = socket.gethostname()
else:
host = self._host
display_host = (
"[%s]" % host
if ":" in host and not host.startswith("[")
else host
if not self._url:
if self._auto_wildcard:
display_host = socket.getfqdn()
# Confirm that the connection is open, otherwise change to `localhost`
try:
socket.create_connection(
(display_host, self.server_port), timeout=1
)
except socket.error as e:
display_host = "localhost"

else:
host = self._host
display_host = (
"[%s]" % host
if ":" in host and not host.startswith("[")
else host
)
self._url = "http://%s:%d%s/" % (
display_host,
self.server_port,
self._flags.path_prefix.rstrip("/"),
)
return "http://%s:%d%s/" % (
display_host,
self.server_port,
self._flags.path_prefix.rstrip("/"),
)
return self._url

def print_serving_message(self):
if self._flags.host is None and not self._flags.bind_all:
Expand Down

0 comments on commit 9465b89

Please sign in to comment.