question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TensorBoard in Jupyter "localhost refused to connect" issue on Windows

See original GitHub issue

ENVIRONMENT: 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:

  1. Jupyter is effectively a server running under my OS (Windows 10)
  2. Processes within Jupyter run under that server/kernel
  3. If I have installed Tensorflow from a Jupyter notebook then all elements should be available within that ‘virtualenv’
  4. 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.

  1. Port 8888 is reserved on localhost to run Jupyter
  2. Tensorboard wants to use port 6006
  3. 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:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

31reactions
JimmyMcWebcommented, Jul 31, 2019

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:

%tensorboard --logdir {logs_base_dir}  --host localhost

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!

11reactions
wchargincommented, Jul 31, 2019

@JimmyMcWeb: Thanks for the report! Responses below.

So my understanding is this: […]

That’s all correct. Running TensorBoard under Jupyter doesn’t affect the port allocations; ports are a system-global resource.

The error message is this:

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.

I’ve tried to guess how to use !kill 17596 but I am not guessing correctly!

On Linux or macOS, you just write !kill 17596 in any IPython notebook cell, or kill 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!

In a nutshell I want to clear out the system memory and just run Tensorboard again

For a quick workaround, you can run the following commands in any command prompt (cmd.exe):

taskkill /im tensorboard.exe /f
del /q %TMP%\.tensorboard-info\*

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to open Tensorboard in browser - Stack Overflow
First of all, make sure the port you use for Tensorboard is opened to the outside world. To make this possible run your...
Read more >
Cannot connect to Tensorboard in JupyterLab - Renku forum
I am unable to connect to tensorboard from a JupyterLab session on limited.renku. I am using a chrome browser, but the error persists...
Read more >
Using TensorBoard in Notebooks - TensorFlow
Start by installing TF 2.0 and loading the TensorBoard notebook extension: For Jupyter users: If you've installed Jupyter and TensorBoard into ...
Read more >
"localhost refused to connect", Tensorboard page completely ...
I can't get TensorBoard to show anything but a blank page (not even a header or anything) when loading "localhost:6006" in my Chrome...
Read more >
How to run TensorBoard in Jupyter Notebook - DLology
In this tutorial, I will show you how seamless it is to run and view TensorBoard right inside a hosted or local Jupyter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found