From 1b3fd399976f8c75e61e6c97814d28dc6f3d377b Mon Sep 17 00:00:00 2001 From: Daniel Stonier Date: Mon, 26 Oct 2015 12:47:01 +0900 Subject: [PATCH] Shutdown rospy timers cleanly Timers go off and start periodically running in the background, and will throw exceptions when ros shutdown occurs because of the sleep function. These are impossible to catch as they're off in a background thread and can be cleanly handled as in the code change. Others with the same problem: * [baxter examples](https://github.com/RethinkRobotics/baxter_examples/issues/48) --- clients/rospy/src/rospy/timer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clients/rospy/src/rospy/timer.py b/clients/rospy/src/rospy/timer.py index e0197f61d6..1f856efc12 100644 --- a/clients/rospy/src/rospy/timer.py +++ b/clients/rospy/src/rospy/timer.py @@ -210,7 +210,11 @@ def run(self): current_expected = rospy.rostime.get_rostime() + self._period last_expected, last_real, last_duration = None, None, None while not rospy.core.is_shutdown() and not self._shutdown: - r.sleep() + try: + r.sleep() + except rospy.exceptions.ROSInterruptException as e: + if rospy.core.is_shutdown(): + break if self._shutdown: break current_real = rospy.rostime.get_rostime()