44"""Entry point for python -m isaacteleop.cloudxr. Runs CloudXR runtime and WSS proxy; main process winds both down on exit."""
55
66import argparse
7- import asyncio
8- import multiprocessing
97import os
108import signal
11- import sys
12- from datetime import datetime , timezone
9+ import time
1310
1411from isaacteleop import __version__ as isaacteleop_version
15- from isaacteleop .cloudxr .env_config import EnvConfig
16- from isaacteleop .cloudxr .runtime import (
17- check_eula ,
18- latest_runtime_log ,
19- run as runtime_run ,
20- runtime_version ,
21- terminate_or_kill_runtime ,
22- wait_for_runtime_ready ,
23- )
24- from isaacteleop .cloudxr .wss import run as wss_run
12+ from isaacteleop .cloudxr .env_config import get_env_config
13+ from isaacteleop .cloudxr .launcher import CloudXRLauncher
14+ from isaacteleop .cloudxr .runtime import latest_runtime_log , runtime_version
2515
2616
2717def _parse_args () -> argparse .Namespace :
18+ """Parse command-line arguments for the CloudXR runtime entry point."""
2819 parser = argparse .ArgumentParser (description = "CloudXR runtime and WSS proxy" )
2920 parser .add_argument (
3021 "--cloudxr-install-dir" ,
@@ -48,60 +39,50 @@ def _parse_args() -> argparse.Namespace:
4839 return parser .parse_args ()
4940
5041
51- async def _main_async () -> None :
42+ def main () -> None :
43+ """Launch the CloudXR runtime and WSS proxy, then block until interrupted."""
5244 args = _parse_args ()
53- env_cfg = EnvConfig .from_args (args .cloudxr_install_dir , args .cloudxr_env_config )
54- check_eula (accept_eula = args .accept_eula or None )
55- logs_dir_path = env_cfg .ensure_logs_dir ()
56- wss_ts = datetime .now (timezone .utc ).strftime ("%Y-%m-%dT%H%M%SZ" )
57- wss_log_path = logs_dir_path / f"wss.{ wss_ts } .log"
58-
59- runtime_proc = multiprocessing .Process (target = runtime_run )
60- runtime_proc .start ()
61-
62- cxr_ver = runtime_version ()
63- print (
64- f"Running Isaac Teleop \033 [36m{ isaacteleop_version } \033 [0m, CloudXR Runtime \033 [36m{ cxr_ver } \033 [0m"
65- )
66-
67- try :
68- ready = await wait_for_runtime_ready (runtime_proc )
69- if not ready :
70- if not runtime_proc .is_alive () and runtime_proc .exitcode != 0 :
71- sys .exit (
72- runtime_proc .exitcode if runtime_proc .exitcode is not None else 1
73- )
74- print ("CloudXR runtime failed to start, terminating..." )
75- sys .exit (1 )
76-
77- stop = asyncio .get_running_loop ().create_future ()
7845
79- def on_signal () -> None :
80- if not stop .done ():
81- stop .set_result (None )
82-
83- loop = asyncio .get_running_loop ()
84- for sig in (signal .SIGINT , signal .SIGTERM ):
85- loop .add_signal_handler (sig , on_signal )
46+ with CloudXRLauncher (
47+ install_dir = args .cloudxr_install_dir ,
48+ env_config = args .cloudxr_env_config ,
49+ accept_eula = args .accept_eula ,
50+ ) as launcher :
51+ cxr_ver = runtime_version ()
52+ print (
53+ f"Running Isaac Teleop \033 [36m{ isaacteleop_version } \033 [0m, CloudXR Runtime \033 [36m{ cxr_ver } \033 [0m"
54+ )
8655
56+ env_cfg = get_env_config ()
57+ logs_dir_path = env_cfg .ensure_logs_dir ()
8758 cxr_log = latest_runtime_log () or logs_dir_path
8859 print (
8960 f"CloudXR runtime: \033 [36mrunning\033 [0m, log file: \033 [90m{ cxr_log } \033 [0m"
9061 )
62+ wss_log = launcher .wss_log_path
9163 print (
92- f"CloudXR WSS proxy: \033 [36mrunning\033 [0m, log file: \033 [90m{ wss_log_path } \033 [0m"
64+ f"CloudXR WSS proxy: \033 [36mrunning\033 [0m, log file: \033 [90m{ wss_log } \033 [0m"
9365 )
9466 print (
9567 f"Activate CloudXR environment in another terminal: \033 [1;32msource { env_cfg .env_filepath ()} \033 [0m"
9668 )
9769 print ("\033 [33mKeep this terminal open, Ctrl+C to terminate.\033 [0m" )
9870
99- await wss_run (log_file_path = wss_log_path , stop_future = stop )
100- finally :
101- terminate_or_kill_runtime (runtime_proc )
71+ stop = False
72+
73+ def on_signal (sig , frame ):
74+ nonlocal stop
75+ stop = True
76+
77+ signal .signal (signal .SIGINT , on_signal )
78+ signal .signal (signal .SIGTERM , on_signal )
79+
80+ while not stop :
81+ launcher .health_check ()
82+ time .sleep (0.1 )
10283
10384 print ("Stopped." )
10485
10586
10687if __name__ == "__main__" :
107- asyncio . run ( _main_async () )
88+ main ( )
0 commit comments