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

Revision history [back]

click to hide/show revision 1
initial version

rclpy.spin doesn't exit until it receives the ctrl-c signal. I would recommend one of the following:

  • Don't use a spin thread. Manually spin the node with spin_once. At my company we've got a SpinUntil method that will spin the node until a lambda is true, or it times-out and we can handle that case.
  • If you must use a spin thread. In both cases, don't forget to do a join on your spin thread:
    • Use spin_until_future_complete instead of spin. This way you can set the future, and it'll stop the spinning.
    • Use a while still_testing: kind of loop with a spin_once (with the timeout!) so that you only spin as long as you need it to. Once your test is done, then you can still_testing = False in your tear down method and the spinning will eventually stop