Repository: Genesis-Embodied-AI/Genesis
File: genesis/_main.py (Python)

Code before:
        manager = multiprocessing.Manager()
        motors_position = manager.list([0.0 for _ in motors_dof_idx])
        stop_event = multiprocessing.Event()
        gui_process = multiprocessing.Process(
            target=_start_gui, args=(motors_name, motors_position_limit, motors_position, stop_event), daemon=True
        )
        gui_process.start()
    else:
        stop_event = multiprocessing.Event()

    t = 0
    while scene.viewer.is_alive() and not stop_event.is_set():
        # Rotate entity if requested
        if rotate:
            t += 1 / FPS
            entity.set_quat(gs.utils.geom.xyz_to_quat(np.array([0, 0, t * 50]), rpy=True, degrees=True))

        if motors_dof_idx:
            entity.set_dofs_position(
                position=torch.tensor(motors_position),
                dofs_idx_local=motors_dof_idx,
                zero_velocity=True,
            )
        scene.visualizer.update(force=True)
    stop_event.set()
    gui_process.join()


def animate(filename_pattern, fps):
    import glob

    from PIL import Image

    gs.init()
    files = sorted(glob.glob(filename_pattern))
    imgs = []
    for file in files:
        print(f"Loading {file}")
        imgs.append(np.array(Image.open(file)))
    gs.tools.animate(imgs, "video.mp4", fps)


def main():
    parser = argparse.ArgumentParser(description="Genesis CLI")
    subparsers = parser.add_subparsers(dest="command")

    parser_clean = subparsers.add_parser("clean", help="Clean all the files cached by genesis and taichi")

    parser_view = subparsers.add_parser("view", help="Visualize a given asset (mesh/URDF/MJCF)")
    parser_view.add_argument("filename", type=str, help="File to visualize")
    parser_view.add_argument(

Review comment (suggestion):
Right now L199 will give an error
```
local variable 'gui_process' referenced before assignment
```
Change to 
```
if motors_dof_idx:
   gui_process.join()
```

Code after:
        manager = multiprocessing.Manager()
        motors_position = manager.list([0.0 for _ in motors_dof_idx])
        stop_event = multiprocessing.Event()
        gui_process = multiprocessing.Process(
            target=_start_gui, args=(motors_name, motors_position_limit, motors_position, stop_event), daemon=True
        )
        gui_process.start()
    else:
        stop_event = multiprocessing.Event()

    t = 0
    while scene.viewer.is_alive() and not stop_event.is_set():
        # Rotate entity if requested
        if rotate:
            t += 1 / FPS
            entity.set_quat(gs.utils.geom.xyz_to_quat(np.array([0, 0, t * 50]), rpy=True, degrees=True))

        if motors_dof_idx:
            entity.set_dofs_position(
                position=torch.tensor(motors_position),
                dofs_idx_local=motors_dof_idx,
                zero_velocity=True,
            )
        scene.visualizer.update(force=True)
    stop_event.set()
    if motors_dof_idx:
        gui_process.join()


def animate(filename_pattern, fps):
    import glob

    from PIL import Image

    gs.init()
    files = sorted(glob.glob(filename_pattern))
    imgs = []
    for file in files:
        print(f"Loading {file}")
        imgs.append(np.array(Image.open(file)))
    gs.tools.animate(imgs, "video.mp4", fps)


def main():
    parser = argparse.ArgumentParser(description="Genesis CLI")
    subparsers = parser.add_subparsers(dest="command")

    parser_clean = subparsers.add_parser("clean", help="Clean all the files cached by genesis and taichi")

    parser_view = subparsers.add_parser("view", help="Visualize a given asset (mesh/URDF/MJCF)")
    parser_view.add_argument("filename", type=str, help="File to visualize")