While using python\'s cmd.Cmd to create a custom CLI, how do I tell the handler to abort the current line and give me a new prompt?
Here is a minimal example:
You can catch the CTRL-C signal with a signal handler. If you add the code below, the interpreter refuses to quit on CTRL-C:
import signal
def handler(signum, frame):
print 'Caught CTRL-C, press enter to continue'
signal.signal(signal.SIGINT, handler)
If you don't want to press ENTER after each CTRL-C, just let the handler do nothing, which will trap the signal without any effect:
def handler(signum, frame):
""" just do nothing """