failed to exit program
Dear developers,
we found that python actionlib.SimpleActionServer will block to exit program, when we raise an exception. the following codes will reproduce the problem.
import rospy
import actionlib
from actionlib.msg import TestAction
from actionlib.msg import TestActionResult
class test_t( object ):
def procedure( self ):
#rospy.signal_shutdown('signal shutdown') # uncomment to exit program
raise rospy.ROSException('exit program') # raise an exception for test
def goal_callback( self ):
self.goal = self.as_tline.accept_new_goal()
def preempt_callback( self ):
res = TestActionResult()
res.result.result = -1
def __init__( self ):
self.goal = None
self.action_server = actionlib.SimpleActionServer( 'test_action', TestAction, auto_start = False )
self.action_server.register_goal_callback ( self.goal_callback )
self.action_server.register_preempt_callback( self.preempt_callback )
#
self.action_server.start() # if we did not start ActionServer, program will exit properly.
if __name__ == '__main__':
try:
rospy.init_node( 'testnode' )
test = test_t()
test.procedure()
except rospy.ROSException as e:
print( e )
print( 'terminated' ) # we can see this message, but program will never exit.
we can see 'terminated' message on the console, but the program is still running.
only kill -9 PID can stop the program.
to exit this program properly, we need rospy.signal_shutdown() before raising an exception, or do not to start SimpleActionServer by self.action_server.start().
we feel that actionlib.ActionServer.status_timer cannot stop, because that actionlib.ActionServer has no __del__ method to join the thread of the status_timer (in spite of that, actionlib.SimpleActionServer has __del__).
specifications of our development environment:
- Debian Strech
- ROS Melodic
- Actionlib 1.11.13-0stretch.20190606.072225
we hope that it could be help.