Skip to content

tensorboard

start_tensorboard()

Starts a tensorboard server in the background.

Returns:

Name Type Description
process Popen

The process of the tensorboard server.

Examples:

>>> from spotpython.utils.tensorboard import start_tensorboard
>>> process = start_tensorboard()
Source code in spotpython/utils/tensorboard.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def start_tensorboard() -> subprocess.Popen:
    """Starts a tensorboard server in the background.

    Returns:
        process: The process of the tensorboard server.

    Examples:
        >>> from spotpython.utils.tensorboard import start_tensorboard
        >>> process = start_tensorboard()

    """
    cmd = ["tensorboard", "--logdir=./runs"]
    process = subprocess.Popen(cmd)
    return process

stop_tensorboard(process)

Stops a tensorboard server if the process exists.

Parameters:

Name Type Description Default
process Popen

The process of the tensorboard server.

required

Returns:

Type Description
None

None

Examples:

>>> from spotpython.utils.tensorboard import start_tensorboard, stop_tensorboard
>>> process = start_tensorboard()
>>> stop_tensorboard(process)
Source code in spotpython/utils/tensorboard.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def stop_tensorboard(process) -> None:
    """
    Stops a tensorboard server if the process exists.

    Args:
        process (subprocess.Popen): The process of the tensorboard server.

    Returns:
        None

    Examples:
        >>> from spotpython.utils.tensorboard import start_tensorboard, stop_tensorboard
        >>> process = start_tensorboard()
        >>> stop_tensorboard(process)
    """
    if process is not None and process.poll() is None:
        process.terminate()
        process.wait()  # Ensure the process has terminated
    else:
        print("No active tensorboard process found or the process is already terminated.")