0
$\begingroup$

I'm trying to speed up a post-processing pipeline based on ROS and since the data is in a bag file I tried the following architecture:

  1. A node opens the bag with rosbag_py. There's a worker thread that reads the next entry, publishes a msg and waits a threading.event() to be set to true.

  2. A subscriber waits for the post-processing pipeline to finish publishing the results, which releases the wait event from the worker

The idea is go through the bag as fast as possible, being the limiting factor the time that the pipeline takes to process a sample. When testing the implementation, it looks like the way the worker thread interacts with the underlying ROS2 threads end up slowing down the pipeline instead of speeding it up.

How do Python threads interact with ROS? What would be the correct approach to solve this issue?

$\endgroup$
1
  • $\begingroup$ You have provided too little information for us to help. Show us your full code for this node. Also describe the environment: How many topics in the rosbag, and what is the original publishing rate? Are all ros2 nodes running on the same machine? Are you using a simulator? How much time do you expect the pipeline to take to process a message? $\endgroup$ Commented Sep 27 at 14:28

1 Answer 1

0
$\begingroup$

Instead of threading, you can use multiprocessing:

One process reads the bag and publishes messages.

The other process runs your ROS2 node and the post-processing pipeline.

Since processes don’t share the GIL, they can run fully concurrently, and inter-process communication happens via ROS topics.

$\endgroup$
1
  • $\begingroup$ My guess is that the cause of the OP's problem has little to do with python threading. It's more likely they don't understand how to play a rosbag. $\endgroup$ Commented Oct 11 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.