Commit 7e47aee
authored
Use a single executor instance for spinning in client_async_callback. (#382)
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.
Signed-off-by: Chris Lalancette <clalancette@gmail.com>1 parent 65bd653 commit 7e47aee
1 file changed
Lines changed: 7 additions & 3 deletions
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | | - | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
58 | | - | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
65 | | - | |
| 69 | + | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| |||
0 commit comments