Lines Matching refs:signal
2 :mod:`signal` --- Set handlers for asynchronous events
5 .. module:: signal
9 This module provides mechanisms to use signal handlers in Python. Some general
12 * A handler for a particular signal, once set, remains installed until it is
20 * Although Python signal handlers are called asynchronously as far as the Python
26 * When a signal arrives during an I/O operation, it is possible that the I/O
27 operation raises an exception after the signal handler returns. This is
31 * Because the C signal handler always returns, it makes little sense to catch
34 * Python installs a small number of signal handlers by default: :const:`SIGPIPE`
41 simultaneously is: always perform :func:`signal` operations in the main thread
44 can set a new signal handler, and the main thread will be the only one to
45 receive signals (this is enforced by the Python :mod:`signal` module, even
50 The variables defined in the :mod:`signal` module are:
55 This is one of two standard signal handling options; it will simply perform
56 the default function for the signal. For example, on most systems the
63 This is another standard signal handler, which will simply ignore the given
64 signal.
69 All the signal numbers are defined symbolically. For example, the hangup signal
70 is defined as :const:`signal.SIGHUP`; the variable names are identical to the
71 names used in C programs, as found in ``<signal.h>``. The Unix man page for
72 ':c:func:`signal`' lists the existing signals (on some systems this is
73 :manpage:`signal(2)`, on others the list is in :manpage:`signal(7)`). Note that
74 not all systems define the same set of signal names; only those names defined by
80 The signal corresponding to the :kbd:`Ctrl+C` keystroke event. This signal can
90 The signal corresponding to the :kbd:`Ctrl+Break` keystroke event. This signal can
100 One more than the number of the highest signal number.
122 The :mod:`signal` module defines one exception:
126 Raised to signal an error from the underlying :func:`setitimer` or
132 The :mod:`signal` module defines the following functions:
137 If *time* is non-zero, this function requests that a :const:`SIGALRM` signal be
148 Return the current signal handler for the signal *signalnum*. The returned value
150 :const:`signal.SIG_IGN`, :const:`signal.SIG_DFL` or :const:`None`. Here,
151 :const:`signal.SIG_IGN` means that the signal was previously ignored,
152 :const:`signal.SIG_DFL` means that the default way of handling the signal was
153 previously in use, and ``None`` means that the previous signal handler was not
159 Cause the process to sleep until a signal is received; the appropriate handler
161 :manpage:`signal(2)`.)
166 Sets given interval timer (one of :const:`signal.ITIMER_REAL`,
167 :const:`signal.ITIMER_VIRTUAL` or :const:`signal.ITIMER_PROF`) specified
172 When an interval timer fires, a signal is sent to the process.
173 The signal sent is dependent on the timer being used;
174 :const:`signal.ITIMER_REAL` will deliver :const:`SIGALRM`,
175 :const:`signal.ITIMER_VIRTUAL` sends :const:`SIGVTALRM`,
176 and :const:`signal.ITIMER_PROF` will deliver :const:`SIGPROF`.
196 Set the wakeup fd to *fd*. When a signal is received, a ``'\0'`` byte is
198 call, allowing the signal to be fully processed.
215 calls will be restarted when interrupted by signal *signalnum*, otherwise
219 Note that installing a signal handler with :func:`signal` will reset the
221 :c:func:`siginterrupt` with a true *flag* value for the given signal.
226 .. function:: signal(signalnum, handler)
228 Set the handler for signal *signalnum* to the function *handler*. *handler* can
230 special values :const:`signal.SIG_IGN` or :const:`signal.SIG_DFL`. The previous
231 signal handler will be returned (see the description of :func:`getsignal`
232 above). (See the Unix man page :manpage:`signal(2)`.)
238 The *handler* is called with two arguments: the signal number and the current
243 On Windows, :func:`signal` can only be called with :const:`SIGABRT`,
257 before opening the file; if the operation takes too long, the alarm signal will
260 import signal, os
263 print 'Signal handler called with signal', signum
266 # Set the signal handler and a 5-second alarm
267 signal.signal(signal.SIGALRM, handler)
268 signal.alarm(5)
273 signal.alarm(0) # Disable the alarm