pythoncoredumpbackslashctrl

Why does pressing Ctrl-backslash result in core dump?


When I'm in a python application (the python shell, for instance), pressing ctrl + \ results in

>>> Quit (core dumped)

Why is this, and how can I avoid this? It is very inconvenient if application bails out whenever I press ctrl + \ by accident.


Solution

  • The python module signal is convenient to deal with this.

    import signal
    
    # Intercept ctrl-c, ctrl-\ and ctrl-z
    def signal_handler(signal, frame):
        pass
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGQUIT, signal_handler)
    signal.signal(signal.SIGTSTP, signal_handler)
    

    Just add handlers to the signal that (in this case) do nothing.