Skip to content

Commit

Permalink
Convert wait_set functions to pybind11 (#706)
Browse files Browse the repository at this point in the history
* Convert wait_set functions to pybind11

Replaces rclpy_destroy_wait_set with pycapsule destructor for the rcl_wait_set_t type.

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Remove unused variable

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* pass string by reference

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Document pycontext arg

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Throw bad_alloc if PyMem_Malloc fails

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz committed Mar 11, 2021
1 parent ff1d3b0 commit 49f2b1f
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 480 deletions.
1 change: 1 addition & 0 deletions rclpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pybind11_add_module(_rclpy_pybind11 SHARED
src/rclpy/subscription.cpp
src/rclpy/time_point.cpp
src/rclpy/timer.cpp
src/rclpy/wait_set.cpp
)
target_include_directories(_rclpy_pybind11 PRIVATE
src/rclpy/
Expand Down
14 changes: 2 additions & 12 deletions rclpy/rclpy/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@
from rclpy.node import Node # noqa: F401


class _WaitSet:
"""Make sure the wait set gets destroyed when a generator exits."""

def __enter__(self):
self.wait_set = _rclpy.rclpy_get_zero_initialized_wait_set()
return self.wait_set

def __exit__(self, t, v, tb):
_rclpy.rclpy_destroy_wait_set(self.wait_set)


class _WorkTracker:
"""Track the amount of work that is in progress."""

Expand Down Expand Up @@ -521,7 +510,8 @@ def _wait_for_ready_callbacks(
entity_count += waitable.get_num_entities()

# Construct a wait set
with _WaitSet() as wait_set, ExitStack() as context_stack:
wait_set = _rclpy.rclpy_get_zero_initialized_wait_set()
with ExitStack() as context_stack:
sub_capsules = []
for sub in subscriptions:
try:
Expand Down
Loading

0 comments on commit 49f2b1f

Please sign in to comment.