how to delete a subcriber/publisher in rclpy
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).
Asked by johnconn on 2020-12-01 22:25:53 UTC
Answers
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?
Asked by William on 2020-12-18 14:15:29 UTC
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
Asked by johnconn on 2020-12-21 10:31:14 UTC
Hi, I am also facing similar issue. Were you able to find any solution?
Asked by akashbhavsar on 2022-02-23 11:20:37 UTC
I am getting this in galaxy still. I am looking for a way to remove a subscription.
Asked by tompe17 on 2022-08-30 08:10:26 UTC
@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
Asked by dcconner on 2023-07-11 09:13:09 UTC
Comments