def _signal_handler(self, *args, **kwargs): """ Shuts down the Logger """ print("Shutting Down") self.running = False RosThread._signal_handler(*args, **kwargs) TopicMonitor._signal_handler(*args, **kwargs) print("Bye")
def __init__(self): threading.Thread.__init__(self) self.log_cache = [] self.data_file = open(LOG_LOCATION, "a") self.time_last_written = 0 # Setting up threading locks self.log_cache_lock = threading.Lock() self.write_lock = threading.Lock() self.time_last_written_lock = threading.Lock() signal.signal(signal.SIGTERM, self._signal_handler) signal.signal(signal.SIGINT, self._signal_handler) topic_name = "/%s/command/roslog" % socket.gethostname() rospy.Subscriber(topic_name, std_msgs.msg.String, self._ros_command) if WRITE_MAXIMUM_INTERVAL > 0: self.running = True self.start() TopicMonitor.add_callback(self.new_topic)
import time import rospy import std_msgs.msg """ This is an application used as a sample and for debugging. This will subscribe to all topic and dump message data to stdout. This application may be executed from the shell with the command 'roslisten' """ def print_data(topic, datatype, data, timestamp): """ Callback occuring from rospy.subscribe which occurs in RosThread. """ print("Topic: %s data: %s" % (topic, data.data)) def new_topic(topic, datatype): """ Callback fired from TopicMontior mainloop. """ print("Topic %s has been identified with datatype %s" % (topic, datatype)) # We dont log rosout because they are Log objects not Data objects if topic.find("/rosout") == -1: RosThread.subscribe(topic, datatype, print_data) if __name__ == "__main__": TopicMonitor.add_callback(new_topic) while 1: pass
def _signal_handler(*args, **kwargs): RosThread._signal_handler(*args, **kwargs) TopicMonitor._signal_handler(*args, **kwargs) sys.exit(0)