Fix rclpy async executor sleep. (backport #1661)#1676
Open
mergify[bot] wants to merge 1 commit into
Open
Conversation
The python asyncio sleep allows for a bit of clock resolution sloppiness (see https://github.com/python/cpython/blob/50476a7e87926cf6a9ea978943c4a3d5d771c95f/Lib/asyncio/base_events.py#L2036) which means that the asyncio sleep can actually wake up *before* the requested amount of time has passed. This is mostly a problem on Windows, where the tick time is 15ms, and we see some tests in rclpy fail a number of times there before eventually succeeding. There are 2 ways we can fix this: either by making the tests accept some slop, or by making the rclpy AsyncClock sleep go back to sleep if it wakes up early. The former is more like Python's asyncio, the latter is more like the rclcpp RCL_TIME sleep. I chose to go with the latter because this is a robotics framework and waking up too early is as bad as waking up too late. But everyone has to deal with the latter situation *anyway*, so it seems more predictable to always sleep at least the requested amount of time. That's what this commit does. Signed-off-by: Chris Lalancette <clalancette@gmail.com> (cherry picked from commit 1e5e267)
Contributor
fujitatomoya
approved these changes
Jun 2, 2026
Member
|
Could you look into the executor failures in windows CI: https://ci.ros2.org/job/ci_windows/28235/testReport/(root)/projectroot/test_executor/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The python asyncio sleep allows for a bit of clock resolution sloppiness (see https://github.com/python/cpython/blob/50476a7e87926cf6a9ea978943c4a3d5d771c95f/Lib/asyncio/base_events.py#L2036) which means that the asyncio sleep can actually wake up before the requested amount of time has passed. This is mostly a problem on Windows, where the tick time is 15ms, and we see some tests in rclpy fail a number of times there before eventually succeeding.
There are 2 ways we can fix this: either by making the tests accept some slop, or by making the rclpy AsyncClock sleep go back to sleep if it wakes up early. The former is more like Python's asyncio, the latter is more like the rclcpp RCL_TIME sleep.
I chose to go with the latter because this is a robotics framework and waking up too early is as bad as waking up too late. But everyone has to deal with the latter situation anyway, so it seems more predictable to always sleep at least the requested amount of time. That's what this commit does.
Is this user-facing behavior change?
No.
Did you use Generative AI?
Yes, Claude Opus 4.7
Additional Information
N/A
This is an automatic backport of pull request #1661 done by Mergify.