Skip to content
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

Example using spin_some might throw exception #266

Closed
hdino opened this issue Apr 22, 2020 · 5 comments · Fixed by #270
Closed

Example using spin_some might throw exception #266

hdino opened this issue Apr 22, 2020 · 5 comments · Fixed by #270
Labels
help wanted Extra attention is needed

Comments

@hdino
Copy link

hdino commented Apr 22, 2020

The examples in this repository are besides the ROS2 tutorials the first place to learn ROS2. Therefore, many public repositories, for instance of universities or research institutes, contain code that uses exactly the same procedures as shown here.

The minimal_publisher example shows how to use rclcpp::spin_some. However, as pointed out in ros2/rclcpp#1066, rclcpp::spin_some will throw an exception if the program received a SIGINT and processed the shutdown after checking rclcpp::ok(), but before constructing the SingleThreadedExecutor in rclcpp::spin_some. This behaviour can easily be triggered by:

while (rclcpp::ok())
{
    std::this_thread::sleep_for(std::chrono::seconds(1));
    rclcpp::spin_some(ros_node);
}

@fujitatomoya created a working example.

In ros2/rclcpp#1066 we already discussed some possible solutions, but we thought it's better to discuss this issue here. What are your opinions?

@fujitatomoya
Copy link
Collaborator

fujitatomoya commented Apr 22, 2020

suggest to put spin_some in a try-catch block in example code, i guess.

@fujitatomoya
Copy link
Collaborator

@hdino

are you gonna make a PR on this?

@hidmic
Copy link
Contributor

hidmic commented May 7, 2020

@hdino friendly ping.

@hidmic hidmic added enhancement New feature or request help wanted Extra attention is needed and removed enhancement New feature or request labels May 7, 2020
fujitatomoya added a commit to fujitatomoya/examples that referenced this issue May 14, 2020
Signed-off-by: Tomoya.Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya
Copy link
Collaborator

@hdino @hidmic

could you take a look at #270?

jacobperron pushed a commit that referenced this issue May 28, 2020
Signed-off-by: Tomoya.Fujita <Tomoya.Fujita@sony.com>
@luym11
Copy link

luym11 commented Jun 24, 2021

I also recently have the issue of ros2/rclcpp#1066, and the fix I found out is something similar to luym11@26dfef3.
Is this the correct way to do this? I thought that ROS should already have a signal handler such that I do not need to override it like this.
Thanks!

luym11 referenced this issue in luym11/examples Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants