Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

process escalates to SIGTERM before running rospy.on_shutdown()

I am running ROS Melodic.
I have wrote a script that is supposed to launch a param-configured gmapping node and, when it receives a shutdown signal from roscore, it launches the map_saver and quits. The script looks like this:

#!/usr/bin/env python

import rospy
import subprocess


def save_map():
    subprocess.Popen(['rosrun', 'map_server', 'map_saver', '-f', 'mymap']).communicate()


if __name__ == '__main__':
    rospy.init_node('gmapping_and_mapsaver')
    rospy.on_shutdown(save_map)

    pop = subprocess.Popen(['roslaunch', 'foo_pkg', 'gmapping_configured.launch'])

    try:
        pop.communicate()
    except rospy.ROSInterruptException:
        pop.terminate()
        save_map()

This node is launched from a .launch file that also spawns the robot, launches the keyboard teleop and so on.

The issue is that even if I send a CTRL-C command, all the nodes get shutdown correctely but this node escaletes directely to SIGTERM, without launching the save_map() function, nor calling the rospy.on_shutdown() method, that is the same thing.

I have also tried catching a KeyboardInterrupt exception, but with no effects.

process escalates to SIGTERM before running rospy.on_shutdown()

I am running ROS Melodic.
I have wrote a script that is supposed to launch a param-configured gmapping node and, when it receives a shutdown signal from roscore, it launches the map_saver and quits. The script looks like this:

#!/usr/bin/env python

import rospy
import subprocess


def save_map():
    subprocess.Popen(['rosrun', 'map_server', 'map_saver', '-f', 'mymap']).communicate()


if __name__ == '__main__':
    rospy.init_node('gmapping_and_mapsaver')
    rospy.on_shutdown(save_map)

    pop = subprocess.Popen(['roslaunch', 'foo_pkg', 'gmapping_configured.launch'])

    try:
        pop.communicate()
    except rospy.ROSInterruptException:
        pop.terminate()
        save_map()

This node is launched from a .launch file that also spawns the robot, launches the keyboard teleop and so on.

The issue is that even if I send a CTRL-C command, all the nodes get shutdown correctely but this node escaletes directely to SIGTERM, without launching the save_map() function, nor calling the rospy.on_shutdown() method, that is the same thing.

I have also tried catching a KeyboardInterrupt exception, but with no effects.

process escalates to SIGTERM before running rospy.on_shutdown()

I am running ROS Melodic.
I have wrote a script that is supposed to launch a param-configured gmapping node and, when it receives a shutdown signal from roscore, it launches the map_saver and quits. The script looks like this:

#!/usr/bin/env python

import rospy
import subprocess


def save_map():
    subprocess.Popen(['rosrun', 'map_server', 'map_saver', '-f', 'mymap']).communicate()


if __name__ == '__main__':
    rospy.init_node('gmapping_and_mapsaver')
    rospy.on_shutdown(save_map)

    pop = subprocess.Popen(['roslaunch', 'foo_pkg', 'gmapping_configured.launch'])

    try:
        pop.communicate()
    except rospy.ROSInterruptException:
        pop.terminate()
        save_map()

This node is launched from a .launch file that also spawns the robot, launches the keyboard teleop and so on.

The issue is that even if I send a CTRL-C command, all the nodes get shutdown correctely but this node escaletes directely to SIGTERM, without launching the save_map() function, nor calling the rospy.on_shutdown() method, that is the same thing.

I have also tried catching a KeyboardInterrupt exception, but with no effects.