Skip to content
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

Improved Environment Variable Handling for Enhanced Flexibility in TensorBoard Launch #1664

Merged
merged 2 commits into from
Nov 11, 2023
Merged
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
14 changes: 10 additions & 4 deletions library/tensorboard_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
tensorboard_proc = None
TENSORBOARD = 'tensorboard' if os.name == 'posix' else 'tensorboard.exe'

# Set the default tensorboard port
DEFAULT_TENSORBOARD_PORT = 6006

def start_tensorboard(headless, logging_dir, wait_time=5):
global tensorboard_proc

headless_bool = True if headless.get('label') == 'True' else False

# Read the TENSORBOARD_PORT from the environment, or use the default
tensorboard_port = os.environ.get('TENSORBOARD_PORT', DEFAULT_TENSORBOARD_PORT)

if not os.listdir(logging_dir):
log.info('Error: log folder is empty')
msgbox(msg='Error: log folder is empty')
Expand All @@ -30,7 +35,7 @@ def start_tensorboard(headless, logging_dir, wait_time=5):
'--host',
'0.0.0.0',
'--port',
'6006',
str(tensorboard_port),
]

log.info(run_cmd)
Expand All @@ -41,7 +46,7 @@ def start_tensorboard(headless, logging_dir, wait_time=5):
stop_tensorboard()

# Start background process
log.info('Starting tensorboard...')
log.info('Starting TensorBoard on port {}'.format(tensorboard_port))
try:
tensorboard_proc = subprocess.Popen(run_cmd)
except Exception as e:
Expand All @@ -53,8 +58,9 @@ def start_tensorboard(headless, logging_dir, wait_time=5):
time.sleep(wait_time)

# Open the TensorBoard URL in the default browser
log.info('Opening tensorboard url in browser...')
webbrowser.open('http://localhost:6006')
tensorboard_url = f'http://localhost:{tensorboard_port}'
log.info(f'Opening TensorBoard URL in browser: {tensorboard_url}')
webbrowser.open(tensorboard_url)


def stop_tensorboard():
Expand Down
Loading