From 0ebe0e23807819155d027a37ea067bbd3407977b Mon Sep 17 00:00:00 2001 From: ipa-fxm Date: Thu, 19 Jan 2017 14:23:36 +0100 Subject: [PATCH 1/2] rospy.sleep exception handling --- cob_dashboard/scripts/cob_dashboard_aggregator.py | 5 ++++- cob_monitoring/src/hz_monitor.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cob_dashboard/scripts/cob_dashboard_aggregator.py b/cob_dashboard/scripts/cob_dashboard_aggregator.py index 0bd5f22d..55fb500a 100755 --- a/cob_dashboard/scripts/cob_dashboard_aggregator.py +++ b/cob_dashboard/scripts/cob_dashboard_aggregator.py @@ -75,4 +75,7 @@ def publish(self): r = rospy.Rate(1) while not rospy.is_shutdown(): da.publish() - r.sleep() + try: + r.sleep() + except rospy.exceptions.ROSInterruptException as e: + pass diff --git a/cob_monitoring/src/hz_monitor.py b/cob_monitoring/src/hz_monitor.py index 54128bfb..c1064119 100755 --- a/cob_monitoring/src/hz_monitor.py +++ b/cob_monitoring/src/hz_monitor.py @@ -50,7 +50,11 @@ def run(self): break rospy.loginfo("hz monitor is waiting for type of topics %s."%str(self.missing_topics)) self.publish_diagnostics() - r.sleep() + + try: + r.sleep() + except rospy.exceptions.ROSInterruptException as e: + pass # call rostopic hz #rt = rostopic.ROSTopicHz(self.window_size) @@ -65,7 +69,10 @@ def run(self): while not rospy.is_shutdown(): #rt.print_hz() # taken from 'rostopic hz' (/opt/ros/indigo/lib/python2.7/dist-packages/rostopic/__init__.py) self.publish_diagnostics(rt_HZ_store) - r.sleep() + try: + r.sleep() + except rospy.exceptions.ROSInterruptException as e: + pass def publish_diagnostics(self, rt_HZ_store = []): # set desired rates From a7ca78db0f160e900d2e485a6031de2eb3122a67 Mon Sep 17 00:00:00 2001 From: ipa-fxm Date: Fri, 20 Jan 2017 10:44:48 +0100 Subject: [PATCH 2/2] some python3 print fixes --- cob_command_gui/src/knoeppkes.py | 10 +++++----- cob_monitoring/src/cpu_monitor.py | 2 +- cob_monitoring/src/hd_monitor.py | 2 +- cob_monitoring/src/wifi_monitor.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cob_command_gui/src/knoeppkes.py b/cob_command_gui/src/knoeppkes.py index 84d994e4..e7d338d2 100755 --- a/cob_command_gui/src/knoeppkes.py +++ b/cob_command_gui/src/knoeppkes.py @@ -100,8 +100,8 @@ def start(func, args): if(largs[0] == "base"): if(base_diff_enabled): largs.append("diff") - #print "Args", tuple(largs) - #print "func ", func + #print("Args", tuple(largs)) + #print("func ", func) thread.start_new_thread(func,tuple(largs)) # exits silently without evaluating result ## use this function in order to evaluate result of action_handle, i.e. show pop-up or similar @@ -203,7 +203,7 @@ def halt_all(self,component_names): def setEMStop(self, em): if(em): - #print "Emergency Stop Active" + #print("Emergency Stop Active") gtk.threads_enter() self.status_image.set_from_file(roslib.packages.get_pkg_dir("cob_command_gui") + "/common/files/icons/error.png") self.status_label.set_text("EM Stop !") @@ -211,7 +211,7 @@ def setEMStop(self, em): if(self.em_stop == False): self.em_stop = True else: - #print "Status OK" + #print("Status OK") self.status_image.set_from_file(roslib.packages.get_pkg_dir("cob_command_gui") + "/common/files/icons/ok.png") gtk.threads_enter() self.status_label.set_text("Status OK") @@ -301,7 +301,7 @@ def __init__(self): gtk.gdk.threads_leave() def signal_handler(signal, frame): - #print 'You pressed Ctrl+C!' + #print("You pressed Ctrl+C!") gtk.main_quit() if __name__ == "__main__": diff --git a/cob_monitoring/src/cpu_monitor.py b/cob_monitoring/src/cpu_monitor.py index 10e69f07..ef01f775 100755 --- a/cob_monitoring/src/cpu_monitor.py +++ b/cob_monitoring/src/cpu_monitor.py @@ -816,7 +816,7 @@ def publish_stats(self): try: rospy.init_node('cpu_monitor_%s' % hostname) except rospy.exceptions.ROSInitException: - print >> sys.stderr, 'CPU monitor is unable to initialize node. Master may not be running.' + print('CPU monitor is unable to initialize node. Master may not be running.', file=sys.stderr) sys.exit(0) cpu_node = CPUMonitor(hostname, options.diag_hostname) diff --git a/cob_monitoring/src/hd_monitor.py b/cob_monitoring/src/hd_monitor.py index ad74da6e..063c94d0 100755 --- a/cob_monitoring/src/hd_monitor.py +++ b/cob_monitoring/src/hd_monitor.py @@ -375,7 +375,7 @@ def publish_stats(self): node_name = ("hd_monitor_"+hostname).replace ("-", "_") rospy.init_node(node_name) except rospy.exceptions.ROSInitException: - print 'HD monitor is unable to initialize node. Master may not be running.' + print('HD monitor is unable to initialize node. Master may not be running.', file=sys.stderr) sys.exit(0) hd_monitor = hd_monitor(hostname, options.diag_hostname, options.directory) diff --git a/cob_monitoring/src/wifi_monitor.py b/cob_monitoring/src/wifi_monitor.py index 82d96cad..d43f58cf 100755 --- a/cob_monitoring/src/wifi_monitor.py +++ b/cob_monitoring/src/wifi_monitor.py @@ -128,7 +128,7 @@ def publish_stats(self): try: rospy.init_node('ddwrt_diag') except rospy.exceptions.ROSInitException: - print 'Wifi monitor is unable to initialize node. Master may not be running.' + print('Wifi monitor is unable to initialize node. Master may not be running.', file=sys.stderr) sys.exit(2) wifi_monitor = WifiMonitor()