Skip to content

Example using spin_some might throw exception #266

Closed

Description

@hdino

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?

Activity

  1. fujitatomoya commented on Apr 22, 2020

    @fujitatomoya
    Collaborator

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

  2. fujitatomoya commented on Apr 24, 2020

    @fujitatomoya
    Collaborator

    @hdino

    are you gonna make a PR on this?

  3. hidmic commented on May 7, 2020

    @hidmic

    @hdino friendly ping.

  4. added
    enhancement
    help wanted
    and removed
    enhancement
    on May 7, 2020
  5. fujitatomoya commented on May 14, 2020

    @fujitatomoya
    Collaborator

    @hdino @hidmic

    could you take a look at #270?

  6. luym11 commented on Jun 24, 2021

    @luym11

    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!

  7. added a commit that references this issue on Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions