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.
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.
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.
CTRL-\ is the Linux key that generates the QUIT
signal. Generally, that signal causes a program to terminate and dump core. This is a feature of UNIX and Linux, wholly unrelated to Python. (For example, try sleep 30
followed by CTRL-\.)
If you want to disable that feature, use the stty command.
From the Linux command line, before Python starts:
stty quit undef
quit
has been undef
ed –
Rh 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.
© 2022 - 2024 — McMap. All rights reserved.
CTRL + \
is a default shortcut for sendingSIGQUIT
to foreground process. By default,SIGQUIT
causes a core dump. More inman kill
. If you wish, you can remove the shortcut from your terminal perferences. – Hexastichsudo
on my machine because quittingipython
this way changes the output ofstty
– Bigmouth