ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Flask in rosnode can't be terminated by control + C

asked 2020-03-10 16:15:36 -0500

yuheng gravatar image

I try to run flask code in ros like this. Every thing seems good until I try to terminate it by press Contrl + C. But it didn't work... Is there anyone know what's the problem or anyway I can terminate it?

if __name__ == '__main__':
    rospy.init_node('client')
    parser = ROSArgparse(relative='client/')
    args = parser.parse_args()
    client = InteractionClient(args)
    app = Flask(__name__)

    @App.route('/get_image/<int:idx>')
    def image(idx):
        ###The view function for sending images with id
        arr = load_image(idx)
        img = Image.fromarray((arr*255).astype('uint8'))
        # create file-object in memory
        file_object = io.BytesIO()
        # write PNG in file-object
        img.save(file_object, 'PNG')
        # move to beginning of file so `send_file()` it will read from start
        file_object.seek(0)
        return send_file(file_object, mimetype='image/PNG')

    app.run(debug=True)
edit retag flag offensive close merge delete

Comments

This is a flask problem not a ROS problem

stevemacenski gravatar image stevemacenski  ( 2020-03-10 16:33:19 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-12 21:03:30 -0500

Rufus gravatar image

You should disable signal handling by ROS so that the flask app can receive the signal and terminate properly.

Replace your rospy.init_node with this

rospy.init_node("client", disable_signals=True)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-03-10 16:15:36 -0500

Seen: 144 times

Last updated: Aug 12 '21