-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rosbag2_py.Recorder] Should add option to disable signal handling changes #1678
Comments
@EricCousineau-TRI Could you please clarify on what code version or ROS distro you observing the issue that the original signal handler is not called? rosbag2/rosbag2_py/src/rosbag2_py/_transport.cpp Lines 390 to 395 in e01e1ef
It should be already available in the Jazzy Jalisco release.
It only may not call your original signal handler if it was settled up as As regards your request
|
@EricCousineau-TRI After some close consideration and prototyping, I think we can add an option to disable signal handling in the Player and Recorder. However, It will be a new API rather than an extension of the existing one to be able to backport it, at least to Jazzy. Also, when using a new API with Please referer to the #1685 for details. |
@MichaelOrlov Thank you for the thorough information!
This is on
In our case, our signal handler is simply the default Python SIGINT signal handler, accessible via import signal
signal.default_int_handler
Awesome! Thank you for very much for prototyping and considering this. To your earlier point of not introducing the option - I understand that the intent is to ensure clean shutdown / cleanup of the signal handler, and signal handling is one option to do so. However, I would assume that if this were library code, RAII / relying on the calling code to do so is on the onus of the user, e.g. using a That being said, looking at the functionality of Is my read on this correct? If so, then maybe the better route is to provide a separate, more library-like class (i.e., no global side effects like This could live in Also, it seems like there may be some disparity between what is offered between |
@EricCousineau-TRI Yes, your understanding that There are a few reasons for that:
If we would provide just a library kind of Python classes for the player and recorder, it would be a myriad issues from users. I see the real use case when option to disable signal handling in Python API could be useful. |
In our case, we are recording data from a robot with some high-level control in Python, where we denote things as episodes via Python. To simplify / align with our existing data pipeline, we want a per-episode rosbag, avoiding large amounts of delay from using a subprocess, and ensure that we have minimal side effects so that we can stop/start this 100's if not 1000's of times in a single process without worrying about race conditions.
This is a very rough export of my colleague's library code that we are using at TRI: The testing confirms minimal delay from starting/stopping, ensure all data is recorded within that bounds, and that we can ensure that we have no issues with Ctrl+C / SIGINT signaling. At a very high-level, the use case is roughly something like this in a gymnasium-like API: for episode_index in episode_indices:
obs, ... = env.reset()
rosbag_recorder.start(get_rosbag_file(episode_index))
done = False
while not done:
act = agent.sample_action(obs)
obs, ... = env.step(act)
rosbag.stop() Inside this loop, we record low-rate data (at rate of agent / env), but we also want related high-rate data, hence this approach. |
@EricCousineau-TRI Thank you for providing a use-case example, and sorry for my late response. I forgot to mention in my previous post about the third very important reason why As far as I see from your example having Python API to the exact same library kind of recorder and player as we have on the C++ layer will not be helpful in your scenario. Please note that we already have a C++ API for the recorder start and stop as well as bag_split. The only missing parts are the init and extension of the bag_split with the provisioning filename. Also, we will need to bring those APIs to the Python interface. |
Our example does what you mentioned - spinning in C++, and only exposes start (with new bag file) / stop / cancel to Python using |
Description
We are launching a
rosbag2_py.Recorder()
instance inside of Python, and related to #1458, we do not want this to affect any surrounding control flow.Additionally, for now (perhaps prototyping, perhaps long-term), the current service options do not allow us to change the output bag path.
We are able to achieve this with some level of hacking:
Related Issues
See #1458
Completion Criteria
There is an option or some mechanism to disable any signal handling within
rosbag2_py.Recorder
.Implementation Notes / Suggestions
Something like
record_options.install_signal_handlers = False
.Testing Notes / Suggestions
Something like the following seems to be sufficient testing:
The text was updated successfully, but these errors were encountered: