Skip to content

Allow TensorBoard to load despite existing MIME type misconfiguration #16203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/16072.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Workaround existing MIME type misconfiguration on Windows preventing TensorBoard from loading when starting TensorBoard.
10 changes: 9 additions & 1 deletion pythonFiles/tensorboard_launcher.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import time
import sys
import os
from tensorboard import default
import mimetypes
from tensorboard import program


def main(logdir):
# Environment variable for PyTorch profiler TensorBoard plugin
# to detect when it's running inside VS Code
os.environ["VSCODE_TENSORBOARD_LAUNCH"] = "1"

# Work around incorrectly configured MIME types on Windows
mimetypes.add_type("application/javascript", ".js")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this is already there? Does mimetypes just ignore the call?

Copy link
Author

@joyceerhl joyceerhl May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://docs.python.org/3/library/mimetypes.html, "When the extension is already known, the new type will replace the old one. When the type is already known the extension will be added to the list of known extensions."

i.e. if .js is mapped to something else, the existing type will be overwritten by what we specify. For context, TensorBoard has done the exact same thing in their CLI launcher codepath for over a year: https://github.com/tensorflow/tensorboard/blob/ea18bb76ebd515f80a7d99656bb08c045638a991/tensorboard/program.py#L392 We don't benefit from that code because we're launching from their Python API entrypoint, namely the launch() function, so this PR just applies the fix they already have to our codepath as well.


# Start TensorBoard using their Python API
tb = program.TensorBoard()
tb.configure(bind_all=False, logdir=logdir)
url = tb.launch()
sys.stdout.write("TensorBoard started at %s\n" % (url))
sys.stdout.flush()

while True:
try:
time.sleep(60)
Expand Down