From b054b4592afdd75bcf7bf9328be70267f28901c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20G=C3=B6rner?= Date: Wed, 6 Jul 2022 19:23:03 +0200 Subject: [PATCH] support `rosbag play --loop` in `rospy.Timer` I fail to understand why this issue still exists after all these years. Without the patch the Timer thread just dies on rosbag loop *with no way of detecting and restarting it* easily. Instead the patch changes the behavior to assume it slept enough and calls the callback. If application logic requires resets, this can be detected from the TimerEvent passed to the callback. --- clients/rospy/src/rospy/timer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clients/rospy/src/rospy/timer.py b/clients/rospy/src/rospy/timer.py index e495bf1a4d..62f2a24282 100644 --- a/clients/rospy/src/rospy/timer.py +++ b/clients/rospy/src/rospy/timer.py @@ -226,6 +226,9 @@ def run(self): while not rospy.core.is_shutdown() and not self._shutdown: try: r.sleep() + except rospy.exceptions.ROSTimeMovedBackwardsException: + # avoid killing the timer just because a rosbag looped + pass except rospy.exceptions.ROSInterruptException as e: if rospy.core.is_shutdown(): break