mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
fallback on 127.0.0.1 if localhost cannot be bound
Some (broken) systems cannot bind to localhost. This handles that failure and falls back to 127 as the default
This commit is contained in:
parent
ca95e914cb
commit
c605ea44cc
@ -410,6 +410,19 @@ class NotebookApp(BaseIPythonApplication):
|
||||
ip = Unicode('localhost', config=True,
|
||||
help="The IP address the notebook server will listen on."
|
||||
)
|
||||
def _ip_default(self):
|
||||
"""Return localhost if available, 127.0.0.1 otherwise.
|
||||
|
||||
On some (horribly broken) systems, localhost cannot be bound.
|
||||
"""
|
||||
s = socket.socket()
|
||||
try:
|
||||
s.bind(('localhost', 0))
|
||||
except socket.error:
|
||||
return '127.0.0.1'
|
||||
else:
|
||||
s.close()
|
||||
return 'localhost'
|
||||
|
||||
def _ip_changed(self, name, old, new):
|
||||
if new == u'*': self.ip = u''
|
||||
|
Loading…
Reference in New Issue
Block a user