Skip to content

Commit d151be0

Browse files
authored
manager: launch TENSORBOARD_BINARY if available (#2386)
Summary: This enables specifying the TensorBoard binary with an environment variable. Callers previously needed to set up a `PATH` with a custom binary; this is simpler and less intrusive. (Googlers, see comments on <http://cl/236333099> for context.) Test Plan: The newly added test fails before this change and passes after it. wchargin-branch: tensorboard-binary
1 parent 63ab35a commit d151be0

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

tensorboard/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,10 @@ def start(arguments, timeout=datetime.timedelta(seconds=60)):
397397
(stdout_fd, stdout_path) = tempfile.mkstemp(prefix=".tensorboard-stdout-")
398398
(stderr_fd, stderr_path) = tempfile.mkstemp(prefix=".tensorboard-stderr-")
399399
start_time_seconds = time.time()
400+
tensorboard_binary = os.environ.get("TENSORBOARD_BINARY", "tensorboard")
400401
try:
401402
p = subprocess.Popen(
402-
["tensorboard"] + arguments,
403+
[tensorboard_binary] + arguments,
403404
stdout=stdout_fd,
404405
stderr=stderr_fd,
405406
)

tensorboard/manager_e2e_test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,40 @@ def test_timeout(self):
319319
self.assertEqual(start_result, manager.StartTimedOut(pid=expected_pid))
320320
self.assertEqual(manager.get_all(), [])
321321

322+
def test_tensorboard_binary_environment_variable(self):
323+
if os.name == "nt":
324+
# TODO(@wchargin): This could in principle work on Windows.
325+
self.skipTest("Requires a POSIX shell for the stub script.")
326+
tempdir = tempfile.mkdtemp()
327+
filepath = os.path.join(tempdir, "tensorbad")
328+
program = textwrap.dedent(
329+
r"""
330+
#!/bin/sh
331+
printf >&2 'tensorbad: fatal: something bad happened\n'
332+
printf 'tensorbad: also some stdout\n'
333+
exit 77
334+
""".lstrip()
335+
)
336+
with open(filepath, "w") as outfile:
337+
outfile.write(program)
338+
os.chmod(filepath, 0o777)
339+
environ = {"TENSORBOARD_BINARY": filepath}
340+
environ_patcher = mock.patch.dict(os.environ, environ)
341+
environ_patcher.start()
342+
self.addCleanup(environ_patcher.stop)
343+
344+
start_result = manager.start(["--logdir=./logs", "--port=0"])
345+
self.assertIsInstance(start_result, manager.StartFailed)
346+
self.assertEqual(
347+
start_result,
348+
manager.StartFailed(
349+
exit_code=77,
350+
stderr="tensorbad: fatal: something bad happened\n",
351+
stdout="tensorbad: also some stdout\n",
352+
),
353+
)
354+
self.assertEqual(manager.get_all(), [])
355+
322356

323357
if __name__ == "__main__":
324358
tf.test.main()

0 commit comments

Comments
 (0)