Skip to content

Commit 12430bb

Browse files
committed
TeleopPanel: use external sim_lock instead of class-level _sim_lock
Replace the class-level _sim_lock with a sim_lock parameter passed from SimContext. This ensures teleop, the physics inputhook, and any other thread all share the same RLock — preventing concurrent MuJoCo access. Part of personalrobotics/mj_manipulator#40
1 parent 7105f80 commit 12430bb

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/mj_viser/teleop_panel.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ class TeleopPanel(PanelBase):
193193
arm_label: Display label (e.g., "Right Arm").
194194
"""
195195

196-
# Shared lock across all TeleopPanel instances — prevents concurrent
197-
# MuJoCo access when multiple arms are teleoped simultaneously.
198-
_sim_lock = threading.Lock()
199-
200196
def __init__(
201197
self,
202198
arm: Arm,
@@ -207,6 +203,7 @@ def __init__(
207203
arm_label: str = "Arm",
208204
abort_fn: object | None = None,
209205
clear_abort_fn: object | None = None,
206+
sim_lock: object | None = None,
210207
):
211208
self._arm = arm
212209
self._controller = controller
@@ -216,6 +213,7 @@ def __init__(
216213
self._arm_label = arm_label
217214
self._abort_fn = abort_fn # callable → bool, checked in teleop loop
218215
self._clear_abort_fn = clear_abort_fn # callable → None, clears abort
216+
self._sim_lock = sim_lock # RLock from SimContext
219217
self._gizmo = None
220218
self._ghost = None
221219
self._is_teleop_active = False
@@ -368,7 +366,7 @@ def _teleop_loop(self) -> None:
368366
try:
369367
from mj_manipulator.teleop import TeleopState
370368

371-
with TeleopPanel._sim_lock:
369+
with self._sim_lock:
372370
state = self._controller.step()
373371
if self._viewer is not None:
374372
self._viewer.sync()

0 commit comments

Comments
 (0)