I will try to explain briefly. I am programming a tool to cut .bag files, for example, according to an initial and ending time. Everything is handled by a GUI. In this interface, there is a progress-bar which shows the time-progress (which it may take a while if the .bag is large). Once the output .bag file is created with the desired messages in the new time range, it displays a description in the GUI.
To do so, I need multiple-threads. I have a thread where I perform the cutting process. The problem is that it does not write anything into the output .bag file. It obtains the Input .bag and creates an output .bag, but this last one is totally empty.
This is the thread, just part of my code:
class TaskThread(QtCore.QThread):
# Signals to communicate with GUI
taskFinished = QtCore.pyqtSignal()
outputdescriptionChanged = QtCore.pyqtSignal(str)
def __init__(self):
QtCore.QThread.__init__(self)
def __del__(self):
self.wait()
def run(self):
print "Executing functions within THREAD..."
# Function to convert times to UNIX timestamps
new_start_datetime_unix, new_end_datetime_unix = time_converter_to_unix(self.start_dt, self.start_dt) # --> Function outside the thread to obtains times from GUI (works fine)
# Input/Output .bag files
print ""
print "Input .bag file path: ", self.input_dt
print "Output .bag file path: ", self.output_dt
# Create new .bag file and write every message between both times
print "Starting to write"
with rosbag.Bag(self.output_dt, 'w') as outbag:
for topic, msg, t in rosbag.Bag(self.input_dt).read_messages(topics = self.topics_dt, start_time = rospy.Time.from_sec(new_start_datetime_unix), end_time = rospy.Time.from_sec(new_end_datetime_unix)):
outbag.write(topic, msg, t)
print "Writing..."
print "Writing finished"
# Create .txt file with output .bag description
output_txtfile(self, self.output_dt) # <--- Function outside the thread to write txt files (works fine)
print "Finishing functions within THREAD..."
print "Finishing thread..."
self.taskFinished.emit()
Result: The terminal prints "Starting to write..." and directly goess to "Writing finished". It creates even the output .bag (so the line with *with rosbag.Bag(self.output_dt, 'w') as outbag:* it works). But it does not write.
The same code without threads works perfectly and writes the messages correclty.
Is there some problem writing .bag files inside threads? Did you experience something similar using the rosbag API?
Thanks,
↧