Fix websocket disconnect by lazily initializing current_sim when None
Browse files
frontend/interactive_server.py
CHANGED
|
@@ -562,6 +562,21 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 562 |
def init_sim():
|
| 563 |
global current_sim
|
| 564 |
with pybullet_lock:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
is_connected = False
|
| 566 |
if current_sim is not None and current_sim.client is not None:
|
| 567 |
try:
|
|
|
|
| 562 |
def init_sim():
|
| 563 |
global current_sim
|
| 564 |
with pybullet_lock:
|
| 565 |
+
if current_sim is None:
|
| 566 |
+
print("Initializing PandaApp lazily in websocket_endpoint...", flush=True)
|
| 567 |
+
env_path = os.path.join(PROJECT_SRC, "envs", "env1.json")
|
| 568 |
+
try:
|
| 569 |
+
current_sim = PandaApp(
|
| 570 |
+
env_json_path=env_path,
|
| 571 |
+
gui=False,
|
| 572 |
+
seed=0,
|
| 573 |
+
agent=None,
|
| 574 |
+
viz=False
|
| 575 |
+
)
|
| 576 |
+
except Exception as e:
|
| 577 |
+
print(f"Failed to initialize lazy PandaApp: {e}", flush=True)
|
| 578 |
+
raise e
|
| 579 |
+
|
| 580 |
is_connected = False
|
| 581 |
if current_sim is not None and current_sim.client is not None:
|
| 582 |
try:
|