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

Revision history [back]

There is probably better ways to do what you want to do but for your case, you could catch the SIGINT signal and then restart your function

!/usr/bin/env python

import signal import sys def signal_handler(signal, frame): print('You pressed Ctrl+C!')

    robot_exec()

signal.signal(signal.SIGINT, signal_handler)

There is probably better ways to do what you want to do but for your case, you could catch the SIGINT signal and then restart your functionfunction. Try adding this to your code

!/usr/bin/env python

import signal
import sys
def signal_handler(signal, frame):
        print('You pressed Ctrl+C!')

Ctrl+C!')
        #Reexecute function
        robot_exec()
signal.signal(signal.SIGINT, signal_handler)

signal.signal(signal.SIGINT, signal_handler)