Skip to content

Commit 238eafc

Browse files
authored
Properly implement action server/client handle cleanup. (#905)
* Properly implement action server/client handle cleanup. In particular, it should never really be the case that the underlying handle that we are using is None. That only seemed to be happening because we were double destroying; once in the explicit call to destroy(), and once in __del__. But we don't actually need __del__; during garbage collection, we'll drop the reference to the handle and then the underlying object will get freed anyway. Just remove all of that extraneous infrastructure here. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 53771be commit 238eafc

File tree

2 files changed

+2
-30
lines changed

2 files changed

+2
-30
lines changed

rclpy/rclpy/action/client.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,9 @@ def add_to_wait_set(self, wait_set):
353353
self._client_handle.add_to_waitset(wait_set)
354354

355355
def __enter__(self):
356-
if self._client_handle is None:
357-
return None
358-
359356
return self._client_handle.__enter__()
360357

361358
def __exit__(self, t, v, tb):
362-
if self._client_handle is None:
363-
return
364-
365359
self._client_handle.__exit__(t, v, tb)
366360

367361
# End Waitable API
@@ -589,13 +583,5 @@ def wait_for_server(self, timeout_sec=None):
589583

590584
def destroy(self):
591585
"""Destroy the underlying action client handle."""
592-
if self._client_handle is None:
593-
return
594-
with self._node.handle:
595-
self._client_handle.destroy_when_not_in_use()
596-
self._node.remove_waitable(self)
597-
self._client_handle = None
598-
599-
def __del__(self):
600-
"""Destroy the underlying action client handle."""
601-
self.destroy()
586+
self._client_handle.destroy_when_not_in_use()
587+
self._node.remove_waitable(self)

rclpy/rclpy/action/server.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,9 @@ def add_to_wait_set(self, wait_set):
495495
self._handle.add_to_waitset(wait_set)
496496

497497
def __enter__(self):
498-
if self._handle is None:
499-
return None
500-
501498
return self._handle.__enter__()
502499

503500
def __exit__(self, t, v, tb):
504-
if self._handle is None:
505-
return
506-
507501
self._handle.__exit__(t, v, tb)
508502

509503
# End Waitable API
@@ -602,16 +596,8 @@ def register_execute_callback(self, execute_callback):
602596

603597
def destroy(self):
604598
"""Destroy the underlying action server handle."""
605-
if self._handle is None:
606-
return
607-
608599
for goal_handle in self._goal_handles.values():
609600
goal_handle.destroy()
610601

611602
self._handle.destroy_when_not_in_use()
612603
self._node.remove_waitable(self)
613-
self._handle = None
614-
615-
def __del__(self):
616-
"""Destroy the underlying action server handle."""
617-
self.destroy()

0 commit comments

Comments
 (0)