ros2 / examples

Example packages for ROS 2
Apache License 2.0
703 stars 312 forks source link

Use a single executor instance for spinning in client_async_callback. (backport #382) #385

Open mergify[bot] opened 4 months ago

mergify[bot] commented 4 months ago

In the current code, it calls rclpy.spin_once(), which instantiates a new executor, adds the node to it, executors one work item, then removes the node and destroys the executor.

Besides being inefficient, the problem with that sequence is that adding a node to the executor actually ends up being an "event", and so the work item that gets returned can be just the work of adding the node, over and over again. For reasons I admit I don't fully understand, this only happens with rmw_cyclonedds_cpp, not with rmw_fastrtps_cpp.

Regardless, the much more performant thing to do is to create an executor at the beginning of the example and to just spin on that. This eliminates adding it to the node constantly, and makes this work with all RMWs.


This is an automatic backport of pull request #382 done by Mergify.

mergify[bot] commented 4 months ago

Cherry-pick of 7e47aee77b7558d7d587c980cf874cbf6b2c451b has failed:

On branch mergify/bp/jazzy/pr-382
Your branch is up to date with 'origin/jazzy'.

You are currently cherry-picking commit 7e47aee.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
    both modified:   rclpy/services/minimal_client/examples_rclpy_minimal_client/client_async_callback.py

no changes added to commit (use "git add" and/or "git commit -a")

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

ahcorde commented 4 months ago

@clalancette probably we should backport this other one too https://github.com/ros2/examples/pull/379/files