Repository navigation
moveit_py: release the GIL in plan(), the collision checks and set_from_ik (backport #3935) - #3985
Merged
Merged
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 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * moveit_py: plan() note as a Note section, warn that read_only() is a shared lock Co-Authored-By: Claude Opus 5.5 <[email protected]> * 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 <[email protected]> --------- Co-authored-by: Matthijs van der Burgh <[email protected]> Co-authored-by: Nathan Brooks <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit b9bf61e)
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Author
|
This pull request is merged. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## humble #3985 +/- ##
==========================================
+ Coverage 51.20% 51.22% +0.02%
==========================================
Files 407 407
Lines 30672 30683 +11
==========================================
+ Hits 15704 15715 +11
Misses 14968 14968 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
MatthijsBurgh
approved these changes
Nov 23, 2026
Contributor
130s
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).