ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

how to delete a subcriber/publisher in rclpy

asked 2020-12-01 21:25:53 -0600

johnconn gravatar image

updated 2020-12-01 21:44:45 -0600

How do I delete publishers and subscriptions with ros2 rclpy?

I tried doing node.destroy_subscription(subscription) and this appears to work,

and this seems to work most of the time, but every once in a while I get the error

The following exception was never retrieved: Tried to use a handle that has been destroyed.

And then my node is broken (pub/subs no longer work and the node's clock gets stuck).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-12-18 13:15:29 -0600

William gravatar image

Using node.destroy_subscription(subscription) is the "right way" to do things. It seems like you're encountering a bug, could you include a bit more error context (maybe just more of the console output even if it doesn't seem relevant)?

It's also useful to have a minimal example that could replicate the issue.

If you want to open an issue against https://github.com/ros2/rclpy/issues, I think this would be appropriate given that you're doing the right thing, just getting an unexpected error.

Also, since this question is a bit old (sorry), maybe you solved it already?

edit flag offensive delete link more

Comments

I never solved it. I worked around the issue by preventing pub/sub deletion. I was trying to port bondpy to ros2, and the existing implementation would delete pub/sub of the bond whenever the bond died or was deallocated

johnconn gravatar image johnconn  ( 2020-12-21 09:31:14 -0600 )edit

Hi, I am also facing similar issue. Were you able to find any solution?

akashbhavsar gravatar image akashbhavsar  ( 2022-02-23 10:20:37 -0600 )edit

I am getting this in galaxy still. I am looking for a way to remove a subscription.

tompe17 gravatar image tompe17  ( 2022-08-30 08:10:26 -0600 )edit

@William I wonder if anyone has more insight into this. I have similar issue where I have a node that needs to create subscription for while, then it not longer needs it for a while, then may need again. If I don't destroy_subscription and recreate, then I get multiple callbacks for one published topic. If I do destroy using node.destroy_subscription then I sometimes get rclpy._rclpy_pybind11.InvalidHandle: cannot use Destroyable because destruction was requested

This causes node shutdown. It is definitely a race condition, and I get similar behavior in Humble with both Cyclone and rmw_fastrtps_cpp

I'm using a MultiThreadedExecutor

dcconner gravatar image dcconner  ( 2023-07-11 09:13:09 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2020-12-01 21:25:53 -0600

Seen: 3,586 times

Last updated: Dec 18 '20