Skip to content

Force-release camera/serial resources when a device disconnect fails#47

Open
nobullryder wants to merge 1 commit into
huggingface:mainfrom
nobullryder:device-cleanup
Open

Force-release camera/serial resources when a device disconnect fails#47
nobullryder wants to merge 1 commit into
huggingface:mainfrom
nobullryder:device-cleanup

Conversation

@nobullryder

Copy link
Copy Markdown

Problem

When LeRobot's device.disconnect() throws (a flaky USB camera or serial port), the underlying handle can stay open — which keeps the camera busy and blocks the next teleop / record / calibrate run from acquiring it.

What this does

safe_disconnect_device() attempts the normal disconnect, and on failure best-effort force-closes the serial/camera resources so the device is actually released. It's wired into teleoperation's teardown here; calibration and recording can adopt the same helper in follow-ups.

Tests

tests/test_devices.py covers the success path and the disconnect-fails-then-force-release path.

🤖 Generated with Claude Code

When LeRobot's device.disconnect() throws (a flaky USB camera or serial port),
the underlying handle can stay open — which keeps the camera busy and blocks the
next teleop/record/calibrate run from acquiring it.

Add safe_disconnect_device(): attempt the normal disconnect, and on failure
best-effort force-close the serial/camera resources so the device is actually
released. Wire it into teleoperation's teardown; other call sites (calibration,
recording) can adopt the same helper in follow-ups.

Tests in tests/test_devices.py cover the success path and the
disconnect-fails-then-force-release path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant