Ask Your Question

High rates of corrupt bags with rosbag python api?

asked 2018-01-30 13:10:43 -0500

lucasw gravatar image

updated 2018-01-30 15:03:19 -0500

I have a python action server where the callback creates a rosbag.Bag and then callback subscribing to various messages then write to that bag, and when the action is over the bag is closed and the callbacks then return without attempting to write.

It appears that about 30%-50% of the bags that come out of this say they need to be reindexed, and then after rosbag reindex a huge amount of the messages are lost- what ought to be hundreds of messages are now 10s or even zero- sometimes the reindexed bag is the same size as orig, other times smaller.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-01-30 13:12:42 -0500

lucasw gravatar image

updated 2018-01-31 13:28:42 -0500

I'm pretty sure that using threading Lock acquire-release around all bag writes will solve this, I'll update this once I have it working (this occurred to me as I was writing the question, but this should be useful for others that make the same mistake).

Note that the rosbag API's are not thread-safe for reading and writing any given bag file. Users of the APIs must ensure no concurrent input/output operations are performed on different threads.

This appears to be working, haven't seen a corrupt bag yet:

from threading import Lock

class Blah:
    def __init__(self):
        self.lock = Lock()
        self.bag = rosbag(filename, 'w')
    def foo_callback(self, msg):
        self.bag.write("foo", msg)
edit flag offensive delete link more



Yeah rqt_bag has similar issues and has a global lock to protect the Bag object.

ahendrix gravatar image ahendrix  ( 2018-01-30 14:34:11 -0500 )edit

Save my day! Thanks for sharing!

codezs09 gravatar image codezs09  ( 2021-01-07 19:59:57 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-01-30 13:10:43 -0500

Seen: 300 times

Last updated: Jan 31 '18