Original code copyright (C) 2009-2022 Rudolf Cardinal (email@example.com).
This file is part of cardinal_pythonlib.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Support functions to handle OS signals that may cause trouble.
ctrl_break_trapper(signum: int, stackframe) → None¶
CTRL-BREAKhas been pressed but does nothing else.
ctrl_c_trapper(signum: int, stackframe) → None¶
CTRL-Chas been pressed but does nothing else.
sigterm_trapper(signum: int, stackframe) → None¶
SIGTERMhas been received but does nothing else.
trap_ctrl_c_ctrl_break() → None¶
CTRL-BREAK, and similar signals from doing anything.
Under Windows, the only options are:
Signal Meaning Comment SIGABRT abnormal termination SIGFPE floating-point error SIGILL illegal instruction SIGINT CTRL+C signal – trapped here SIGSEGV illegal storage access SIGTERM termination request – trapped here SIGBREAK CTRL+BREAK – trapped here under Windows
In Linux, you also find:
Signal Meaning SIGBUS bus error / unaligned access
To ignore, can do:
signal.signal(signal.SIGINT, signal.SIG_IGN) # SIG_IGN = "ignore me"
or pass a specified handler, as in the code here.