Skip to content

Fix rclpy async executor sleep. (backport #1661)#1676

Open
mergify[bot] wants to merge 1 commit into
lyricalfrom
mergify/bp/lyrical/pr-1661
Open

Fix rclpy async executor sleep. (backport #1661)#1676
mergify[bot] wants to merge 1 commit into
lyricalfrom
mergify/bp/lyrical/pr-1661

Conversation

@mergify

@mergify mergify Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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.

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)
@clalancette

clalancette commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@skyegalaxy

Copy link
Copy Markdown
Member

Could you look into the executor failures in windows CI: https://ci.ros2.org/job/ci_windows/28235/testReport/(root)/projectroot/test_executor/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants