jupyter / jupyter_client

Jupyter protocol client APIs
https://jupyter-client.readthedocs.io
BSD 3-Clause "New" or "Revised" License
379 stars 280 forks source link

Kernel hangs if notebook started on computer without internet #138

Open pqqp opened 8 years ago

pqqp commented 8 years ago

Hangup caused by

PUBLIC_IPS[:] = socket.gethostbyname_ex(socket.gethostname() + '.local')[2]

in file jupyter_client/localinterfaces.py Discussion about gethostbyname with timeout: http://www.gossamer-threads.com/lists/python/python/790534 Some workaround: https://stackoverflow.com/questions/18544514/gethostbyname-exhostname-extremely-slow Please, fix it =)

Carreau commented 8 years ago

Thanks !

If you have an idea on how to fix it, feel free to send a PR !

vidartf commented 8 years ago

I have this issue as well (on Windows 7). It can be replicated by the following code whether connected to the internet or not:

import socket
socket.gethostbyname_ex(socket.gethostname() + '.local')

The code line mentioned above is only called when not connected to the internet, which is why it only hangs when not connected. (I have no suggestion for how to fix this, as I'm not sure what this code line is supposed to do).

( @minrk : You've seen the effect of this :) )

minrk commented 8 years ago

@vidartf ha! So you can blame me 100% for the hang we saw.

This gethostbyname_ex call should only happen if multiple preferred methods are failing. If you can install netifaces, that's the best option. I tried to add a dependency on netifaces, since it's the best option if available, but there are some installation issues preventing us from making a hard dependency. What do you see from:

from jupyter_client.localinterfaces import _load_ips_ipconfig
_load_ips_ipconfig()
vidartf commented 8 years ago

_load_ips_ipconfig() gives None when connected. When not connected, an exception is raised with the following trace:

---------------------------------------------------------------------------
NoIPAddresses                             Traceback (most recent call last)
<ipython-input-6-a59256129546> in <module>()
----> 1 _load_ips_ipconfig()

c:\prog\hyperspyui\python-3.4.3.amd64\lib\site-packages\jupyter_client\localinterfaces.py in _load_i
ps_ipconfig()
    128         if m:
    129             addrs.append(m.group(1))
--> 130     _populate_from_list(addrs)
    131
    132

c:\prog\hyperspyui\python-3.4.3.amd64\lib\site-packages\jupyter_client\localinterfaces.py in _popula
te_from_list(addrs)
     62     """populate local and public IPs from flat list of all IPs"""
     63     if not addrs:
---> 64         raise NoIPAddresses
     65
     66     global LOCALHOST

NoIPAddresses:

Looking at the output from ipconfig, this makes sense, as no IP addresses are given when disconnected (loopback interface is not listed).