cardinal_pythonlib.signalfunc¶
Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.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.
-
cardinal_pythonlib.signalfunc.
ctrl_break_trapper
(signum: int, stackframe) → None[source]¶ Logs that
CTRL-BREAK
has been pressed but does nothing else.
-
cardinal_pythonlib.signalfunc.
ctrl_c_trapper
(signum: int, stackframe) → None[source]¶ Logs that
CTRL-C
has been pressed but does nothing else.
-
cardinal_pythonlib.signalfunc.
sigterm_trapper
(signum: int, stackframe) → None[source]¶ Logs that
SIGTERM
has been received but does nothing else.
-
cardinal_pythonlib.signalfunc.
trap_ctrl_c_ctrl_break
() → None[source]¶ Prevent
CTRL-C
,CTRL-BREAK
, and similar signals from doing anything.See
- https://docs.python.org/3/library/signal.html#signal.SIG_IGN
- https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx
- https://msdn.microsoft.com/en-us/library/windows/desktop/ms682541(v=vs.85).aspx
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.