TensorBoard in Jupyter "localhost refused to connect" issue on Windows
See original GitHub issueENVIRONMENT: About Jupyter Notebook
Server Information: You are using Jupyter notebook.
The version of the notebook server is: 5.7.8 The server is running on this version of Python: Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)]
Current Kernel Information: Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] Type ‘copyright’, ‘credits’ or ‘license’ for more information IPython 7.4.0 – An enhanced Interactive Python. Type ‘?’ for help.
I’m not sure where to start here other than to relay the issue that I can’t fix!
I am learning neural networks and I am trying to run code within Jupyter notebooks.
Tensorboard is a useful visualisation tool and I thought that I had got it to work embedded into a Jupyter notebook. It worked once but then stopped connecting to the localhost.
I’ve tried to follow through solutions to this issue from StackOverflow and GitHub postings but they either reference commands without giving the context (i.e. environment) in which those commands should be executed or they just get closed off because nobody has responded or redirected to here, the Tensorboard hub.
I’m stuck and I am struggling because I don’t fully understand how the various pieces of technology hang together.
So my understanding is this:
- Jupyter is effectively a server running under my OS (Windows 10)
- Processes within Jupyter run under that server/kernel
- If I have installed Tensorflow from a Jupyter notebook then all elements should be available within that ‘virtualenv’
- Tensorboard is bundled with Tensorflow but need to be explicitly loaded from a notebook
What I don’t really understand is how the port numbers are working.
- Port 8888 is reserved on localhost to run Jupyter
- Tensorboard wants to use port 6006
- What effect Tensorboard running under Jupyter has on port allocations, I don’t know.
My code is this:
import os
import tensorflow as tf
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
%load_ext tensorboard
logs_base_dir = "./logs"
os.makedirs(logs_base_dir, exist_ok=True)
%tensorboard --logdir {logs_base_dir}
There are log files in the /logs directory created under another notebook.
The error message is this:
Reusing TensorBoard on port 6006 (pid 17596), started 1 day, 23:56:21 ago. (Use '!kill 17596' to kill it.)
I have shutdown the PC and restarted but this process seems to persist? I can’t find anything on port 6006 when I’ve run: netstat -abno from Windows cmd (as admin)
I’ve tried to guess how to use !kill 17596 but I am not guessing correctly!
In a nutshell I want to clear out the system memory and just run Tensorboard again, but it won’t work! (but it did work once!)
I would be grateful for any help, but please assume that I don’t know from which terminal / notebook commands need to be run from. I’d be grateful if you could make that explicit in any answers / suggestions.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
OK, guess work … but it seems to be responding again.
A quick scan of the docs on this site mentioned network security issue on Macs: https://github.com/tensorflow/tensorboard#i-get-a-network-security-popup-every-time-i-run-tensorboard-on-a-mac
Under that heading it mentioned specifying “localhost” instead of the default “0.0.0.0”
I amended my code above to:
I ran the code again from Jupyter notebook. 1st attempt timed out, 2nd attempt brought up the Tensorboard dashboard, which I will claim is it working now.
Still not sure why it seems to have worked but I’ll accept that right now it is!
@JimmyMcWeb: Thanks for the report! Responses below.
That’s all correct. Running TensorBoard under Jupyter doesn’t affect the port allocations; ports are a system-global resource.
The “Reusing TensorBoard” message isn’t an error; it’s just an informational message. Reusing a previously started TensorBoard instance should usually be fine, but we let you know anyway just in case the instance has somehow gotten into a bad state.
On Linux or macOS, you just write
!kill 17596
in any IPython notebook cell, orkill 17596
(no bang) in any terminal window—but it sounds like you’re on Windows, so the situation is different.I’ve just looked into the details, and it looks like there’s no simple way to achieve the desired behavior on Windows. (You can use
taskkill
to force-kill an arbitrary process given its ID, but as far as I can tell, you can’t gracefully shut down any process unless it’s part of your process group, and even then the situation is a bit complicated.) So we’ll need to make a few structural changes to the notebook integration to make it behave the same as on Linux and macOS.I’ll update the messaging on Windows accordingly—thanks for bringing this to our attention!
For a quick workaround, you can run the following commands in any command prompt (
cmd.exe
):If either of those gives an error (probably “process “tensorboard.exe” not found” or “the system cannot find the file specified”), that’s okay: you can ignore it.