Repository navigation
moveit_py: release the GIL in plan(), the collision checks and set_from_ik (backport #3935) - #3979
mergify[bot] wants to merge 1 commit into
Conversation
…om_ik (#3935) * moveit_py: PlanningComponent.plan() releases the GIL * moveit_py: collision checks and set_from_ik release the GIL * moveit_py: check_self_collision releases the GIL The other collision queries of PlanningScene already do; the three check_self_collision overloads were missed. * moveit_py: note in the docstrings which GIL-releasing calls write state Apply the review suggestions: the calls that write to the object or to the passed state while the GIL is released now say so, and that the object must not be used from another Python thread meanwhile. Co-authored-by: Nathan Brooks <nathanbrooks@picknik.ai> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * moveit_py: plan() note as a Note section, warn that read_only() is a shared lock Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * moveit_py: test that the collision checks release the GIL A second Python thread counts while the main thread runs a collision check in a loop. The switch interval is raised to 30 s, so the counter only advances while the binding releases the GIL: about 3000 ticks in 0.5 s with the guard, 1 without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Matthijs van der Burgh <matthijs.van.der.burgh@vbti.nl> Co-authored-by: Nathan Brooks <nathanbrooks@picknik.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit b9bf61e)
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
Tick the box to add this pull request to the merge queue (same as
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## jazzy #3979 +/- ##
==========================================
+ Coverage 46.27% 46.30% +0.03%
==========================================
Files 718 718
Lines 59236 59254 +18
Branches 7598 7612 +14
==========================================
+ Hits 27405 27430 +25
+ Misses 31666 31659 -7
Partials 165 165 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Target:
main(labelbackport-jazzyfor the Jazzy release the cells run, 2.12.x).Description
PlanningComponent.plan()holds the Python GIL for the whole plan, which can take seconds. Everyother Python thread of the process is frozen for that long: ROS callbacks and timers of the node,
tf listeners, an HTTP server.
MoveItPy.execute()already releases the GIL for the same reason(#2573). This does the same for:
PlanningComponent.plan()(py::call_guard<py::gil_scoped_release>). The two optional Pythoncallbacks (
solution_selection_function,stopping_criterion_callback) keep working: pybind11'sstd::functioncaster takes the GIL back around each call into Python.PlanningScene(is_state_valid,is_state_colliding,check_collision,check_self_collision,is_path_valid) andRobotState.set_from_ik. Theseare the calls a reachability or validity check makes in bulk; released, they can run on worker
threads while the node keeps spinning.
Measured on a Techman TM arm with a Python node that plans while it serves
/statusover HTTP andlistens to tf (MoveIt 2.12.4, Jazzy): with the GIL held,
/statustook up to 2.7 s during moves and5-7 of 20 moves failed with a tf
ExtrapolationException(the Python tf listener lagged 0.76 sbehind) whenever a planning request ran alongside; released,
/statusstayed under 0.4 s and 0 of20 moves failed, over two runs each.
Note for reviewers: with the GIL released, two Python threads can enter the same
PlanningComponent,PlanningSceneorRobotStateat once (for instance, one readsjoint_positionswhile another runsset_from_ikon the same state), which the GIL used to preventas a side effect. Those objects are not thread-safe in C++ either; callers who share one across
threads must serialize their calls themselves (we do so with a per-instance lock). This matches how
execute()behaves today.Checklist
moveit_py/test/unithas no planner orkinematics solver loaded (
test_set_from_ikis commented out for that reason) and theintegration test directory is empty, so a test that measures another thread's progress during
a long
plan()orset_from_ik(timeout=...)call has nowhere to run yet. Happy to add one ifa fixture with a kinematics plugin is acceptable.
Summary by CodeRabbit
This is an automatic backport of pull request #3935 done by [Mergify](https://mergify.com).