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

Short answer: Replace time.sleep with rclpy.spin_once

Long answer: Remember that async != multithreading. When you use async, all the code runs in a single thread. So using a for loop that only runs time.sleep means the only thread you have is now locked, and no other code can be executed. You have to give up control so that call_async can do its job. This can be achieved using rclpy.spin_once. I think it is similar to asyncio.sleep(0).

You can learn more about async in this video (which is fantastic but explains async in javascript; so the syntax is a bit different) and this video that talks about python's async in particular.