Skip to content
Permalink
Branch: master
Find file Copy path
1 contributor

Users who have contributed to this file

executable file 53 lines (45 sloc) 1.38 KB
#!/usr/bin/env python3
import argparse
import os
import subprocess
import socket
import sys
import tempfile
import getpass
parser = argparse.ArgumentParser()
parser.add_argument('run_dirs', nargs='*')
args = parser.parse_args()
def get_open_port():
s = socket.socket()
s.bind(('', 0))
port = s.getsockname()[1]
s.close()
return port
port = get_open_port()
if len(args.run_dirs) == 1:
if not os.path.exists(args.run_dirs[0]):
print(f"Error: path '{args.run_dirs[0]}' does not exist",
file=sys.stderr)
exit(1)
tensorboard_dir = args.run_dirs[0]
else:
tensorboard_dir = tempfile.mkdtemp()
for path in args.run_dirs:
if not os.path.exists(path):
print(f"Error: path '{path}' does not exist", file=sys.stderr)
exit(1)
link = os.path.join(tensorboard_dir, path)
os.makedirs(os.path.dirname(link), exist_ok=True)
os.symlink(os.path.abspath(path), link)
subprocess.run(['pkill', '-f', 'tensorboard --port {}'.format(port)])
proc1 = subprocess.Popen(['tensorboard', '--port', str(port), '--logdir', tensorboard_dir],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("Waiting for TensorBoard to start...")
proc1.stderr.readline()
proc2 = subprocess.Popen(['h', str(port)])
try:
input()
except KeyboardInterrupt:
pass
proc1.terminate()
proc2.terminate()
You can’t perform that action at this time.