2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
:mod:`signal` --- Set handlers for asynchronous events
|
|
|
|
======================================================
|
|
|
|
|
|
|
|
.. module:: signal
|
|
|
|
:synopsis: Set handlers for asynchronous events.
|
|
|
|
|
|
|
|
|
|
|
|
This module provides mechanisms to use signal handlers in Python. Some general
|
|
|
|
rules for working with signals and their handlers:
|
|
|
|
|
|
|
|
* A handler for a particular signal, once set, remains installed until it is
|
|
|
|
explicitly reset (Python emulates the BSD style interface regardless of the
|
|
|
|
underlying implementation), with the exception of the handler for
|
|
|
|
:const:`SIGCHLD`, which follows the underlying implementation.
|
|
|
|
|
|
|
|
* There is no way to "block" signals temporarily from critical sections (since
|
|
|
|
this is not supported by all Unix flavors).
|
|
|
|
|
|
|
|
* Although Python signal handlers are called asynchronously as far as the Python
|
|
|
|
user is concerned, they can only occur between the "atomic" instructions of the
|
|
|
|
Python interpreter. This means that signals arriving during long calculations
|
|
|
|
implemented purely in C (such as regular expression matches on large bodies of
|
|
|
|
text) may be delayed for an arbitrary amount of time.
|
|
|
|
|
|
|
|
* When a signal arrives during an I/O operation, it is possible that the I/O
|
|
|
|
operation raises an exception after the signal handler returns. This is
|
|
|
|
dependent on the underlying Unix system's semantics regarding interrupted system
|
|
|
|
calls.
|
|
|
|
|
|
|
|
* Because the C signal handler always returns, it makes little sense to catch
|
|
|
|
synchronous errors like :const:`SIGFPE` or :const:`SIGSEGV`.
|
|
|
|
|
|
|
|
* Python installs a small number of signal handlers by default: :const:`SIGPIPE`
|
|
|
|
is ignored (so write errors on pipes and sockets can be reported as ordinary
|
|
|
|
Python exceptions) and :const:`SIGINT` is translated into a
|
|
|
|
:exc:`KeyboardInterrupt` exception. All of these can be overridden.
|
|
|
|
|
|
|
|
* Some care must be taken if both signals and threads are used in the same
|
|
|
|
program. The fundamental thing to remember in using signals and threads
|
|
|
|
simultaneously is: always perform :func:`signal` operations in the main thread
|
2008-03-24 10:39:54 -03:00
|
|
|
of execution. Any thread can perform an :func:`alarm`, :func:`getsignal`,
|
|
|
|
:func:`pause`, :func:`setitimer` or :func:`getitimer`; only the main thread
|
|
|
|
can set a new signal handler, and the main thread will be the only one to
|
|
|
|
receive signals (this is enforced by the Python :mod:`signal` module, even
|
|
|
|
if the underlying thread implementation supports sending signals to
|
|
|
|
individual threads). This means that signals can't be used as a means of
|
|
|
|
inter-thread communication. Use locks instead.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The variables defined in the :mod:`signal` module are:
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: SIG_DFL
|
|
|
|
|
|
|
|
This is one of two standard signal handling options; it will simply perform the
|
|
|
|
default function for the signal. For example, on most systems the default
|
|
|
|
action for :const:`SIGQUIT` is to dump core and exit, while the default action
|
|
|
|
for :const:`SIGCLD` is to simply ignore it.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: SIG_IGN
|
|
|
|
|
|
|
|
This is another standard signal handler, which will simply ignore the given
|
|
|
|
signal.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: SIG*
|
|
|
|
|
|
|
|
All the signal numbers are defined symbolically. For example, the hangup signal
|
|
|
|
is defined as :const:`signal.SIGHUP`; the variable names are identical to the
|
|
|
|
names used in C programs, as found in ``<signal.h>``. The Unix man page for
|
|
|
|
':cfunc:`signal`' lists the existing signals (on some systems this is
|
|
|
|
:manpage:`signal(2)`, on others the list is in :manpage:`signal(7)`). Note that
|
|
|
|
not all systems define the same set of signal names; only those names defined by
|
|
|
|
the system are defined by this module.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: NSIG
|
|
|
|
|
|
|
|
One more than the number of the highest signal number.
|
|
|
|
|
2008-03-24 10:39:54 -03:00
|
|
|
|
|
|
|
.. data:: ITIMER_REAL
|
|
|
|
|
|
|
|
Decrements interval timer in real time, and delivers SIGALRM upon expiration.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: ITIMER_VIRTUAL
|
|
|
|
|
|
|
|
Decrements interval timer only when the process is executing, and delivers
|
|
|
|
SIGVTALRM upon expiration.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: ITIMER_PROF
|
|
|
|
|
|
|
|
Decrements interval timer both when the process executes and when the
|
|
|
|
system is executing on behalf of the process. Coupled with ITIMER_VIRTUAL,
|
|
|
|
this timer is usually used to profile the time spent by the application
|
|
|
|
in user and kernel space. SIGPROF is delivered upon expiration.
|
|
|
|
|
|
|
|
|
|
|
|
The :mod:`signal` module defines one exception:
|
|
|
|
|
|
|
|
.. exception:: ItimerError
|
|
|
|
|
|
|
|
Raised to signal an error from the underlying :func:`setitimer` or
|
|
|
|
:func:`getitimer` implementation. Expect this error if an invalid
|
|
|
|
interval timer or a negative time is passed to :func:`setitimer`.
|
|
|
|
This error is a subtype of :exc:`IOError`.
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
The :mod:`signal` module defines the following functions:
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: alarm(time)
|
|
|
|
|
|
|
|
If *time* is non-zero, this function requests that a :const:`SIGALRM` signal be
|
|
|
|
sent to the process in *time* seconds. Any previously scheduled alarm is
|
|
|
|
canceled (only one alarm can be scheduled at any time). The returned value is
|
|
|
|
then the number of seconds before any previously set alarm was to have been
|
|
|
|
delivered. If *time* is zero, no alarm is scheduled, and any scheduled alarm is
|
|
|
|
canceled. If the return value is zero, no alarm is currently scheduled. (See
|
|
|
|
the Unix man page :manpage:`alarm(2)`.) Availability: Unix.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getsignal(signalnum)
|
|
|
|
|
|
|
|
Return the current signal handler for the signal *signalnum*. The returned value
|
|
|
|
may be a callable Python object, or one of the special values
|
|
|
|
:const:`signal.SIG_IGN`, :const:`signal.SIG_DFL` or :const:`None`. Here,
|
|
|
|
:const:`signal.SIG_IGN` means that the signal was previously ignored,
|
|
|
|
:const:`signal.SIG_DFL` means that the default way of handling the signal was
|
|
|
|
previously in use, and ``None`` means that the previous signal handler was not
|
|
|
|
installed from Python.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: pause()
|
|
|
|
|
|
|
|
Cause the process to sleep until a signal is received; the appropriate handler
|
|
|
|
will then be called. Returns nothing. Not on Windows. (See the Unix man page
|
|
|
|
:manpage:`signal(2)`.)
|
|
|
|
|
|
|
|
|
2008-03-24 10:39:54 -03:00
|
|
|
.. function:: setitimer(which, seconds[, interval])
|
|
|
|
|
|
|
|
Sets given itimer (one of :const:`signal.ITIMER_REAL`,
|
|
|
|
:const:`signal.ITIMER_VIRTUAL` or :const:`signal.ITIMER_PROF`) especified
|
|
|
|
by *which* to fire after *seconds* (float is accepted, different from
|
|
|
|
:func:`alarm`) and after that every *interval* seconds. The interval
|
|
|
|
timer specified by *which* can be cleared by setting seconds to zero.
|
|
|
|
|
|
|
|
The old values are returned as a tuple: (delay, interval).
|
|
|
|
|
|
|
|
Attempting to pass an invalid interval timer will cause a
|
|
|
|
:exc:`ItimerError`.
|
|
|
|
|
|
|
|
.. versionadded:: 2.6
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getitimer(which)
|
|
|
|
|
|
|
|
Returns current value of a given itimer especified by *which*.
|
|
|
|
|
|
|
|
.. versionadded:: 2.6
|
|
|
|
|
|
|
|
|
Merged revisions 59565-59594 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59568 | facundo.batista | 2007-12-19 13:53:01 +0100 (Wed, 19 Dec 2007) | 3 lines
Some minor cleanups. Thanks Mark Dickinson.
........
r59573 | raymond.hettinger | 2007-12-19 19:13:31 +0100 (Wed, 19 Dec 2007) | 1 line
Fix issue 1661: Flags argument silently ignored in re functions with compiled regexes.
........
r59574 | guido.van.rossum | 2007-12-19 20:41:06 +0100 (Wed, 19 Dec 2007) | 7 lines
Patch #1583 by Adam Olsen.
This adds signal.set_wakeup_fd(fd) which sets a file descriptor to
which a zero byte will be written whenever a C exception handler runs.
I added a simple C API as well, PySignal_SetWakeupFd(fd).
........
r59575 | raymond.hettinger | 2007-12-19 23:14:34 +0100 (Wed, 19 Dec 2007) | 1 line
Bigger range for non-extended opargs.
........
r59576 | guido.van.rossum | 2007-12-19 23:51:13 +0100 (Wed, 19 Dec 2007) | 5 lines
Patch #1549 by Thomas Herve.
This changes the rules for when __hash__ is inherited slightly,
by allowing it to be inherited when one or more of __lt__, __le__,
__gt__, __ge__ are overridden, as long as __eq__ and __ne__ aren't.
........
r59577 | raymond.hettinger | 2007-12-20 02:25:05 +0100 (Thu, 20 Dec 2007) | 1 line
Add comments
........
r59578 | brett.cannon | 2007-12-20 11:09:52 +0100 (Thu, 20 Dec 2007) | 3 lines
Add tests for the warnings module; specifically formatwarning and showwarning.
Still need tests for warn_explicit and simplefilter.
........
r59582 | guido.van.rossum | 2007-12-20 18:28:10 +0100 (Thu, 20 Dec 2007) | 2 lines
Patch #1672 by Joseph Armbruster. Use tempdir() to get a temporary directory.
........
r59584 | georg.brandl | 2007-12-20 22:03:02 +0100 (Thu, 20 Dec 2007) | 2 lines
Fix refleak introduced in r59576.
........
r59586 | guido.van.rossum | 2007-12-21 00:48:28 +0100 (Fri, 21 Dec 2007) | 4 lines
Improve performance of built-in any()/all() by avoiding PyIter_Next() --
using a trick found in ifilter().
Feel free to backport to 2.5.
........
r59591 | andrew.kuchling | 2007-12-22 18:27:02 +0100 (Sat, 22 Dec 2007) | 1 line
Add item
........
2007-12-24 04:52:31 -04:00
|
|
|
.. function:: set_wakeup_fd(fd)
|
|
|
|
|
|
|
|
Set the wakeup fd to *fd*. When a signal is received, a ``'\0'`` byte is
|
|
|
|
written to the fd. This can be used by a library to wakeup a poll or select
|
|
|
|
call, allowing the signal to be fully processed.
|
|
|
|
|
|
|
|
The old wakeup fd is returned. *fd* must be non-blocking. It is up to the
|
|
|
|
library to remove any bytes before calling poll or select again.
|
|
|
|
|
|
|
|
When threads are enabled, this function can only be called from the main thread;
|
|
|
|
attempting to call it from other threads will cause a :exc:`ValueError`
|
|
|
|
exception to be raised.
|
|
|
|
|
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60964,60966-60967,60971,60977,60979-60989 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60980 | georg.brandl | 2008-02-23 16:02:28 +0100 (Sat, 23 Feb 2008) | 2 lines
#1492: allow overriding BaseHTTPServer's content type for error messages.
........
r60982 | georg.brandl | 2008-02-23 16:06:25 +0100 (Sat, 23 Feb 2008) | 2 lines
#2165: fix test_logging failure on some machines.
........
r60983 | facundo.batista | 2008-02-23 16:07:35 +0100 (Sat, 23 Feb 2008) | 6 lines
Issue 1089358. Adds the siginterrupt() function, that is just a
wrapper around the system call with the same name. Also added
test cases, doc changes and NEWS entry. Thanks Jason and Ralf
Schmitt.
........
r60984 | georg.brandl | 2008-02-23 16:11:18 +0100 (Sat, 23 Feb 2008) | 2 lines
#2067: file.__exit__() now calls subclasses' close() method.
........
r60985 | georg.brandl | 2008-02-23 16:19:54 +0100 (Sat, 23 Feb 2008) | 2 lines
More difflib examples. Written for GHOP by Josip Dzolonga.
........
r60987 | andrew.kuchling | 2008-02-23 16:41:51 +0100 (Sat, 23 Feb 2008) | 1 line
#2072: correct documentation for .rpc_paths
........
r60988 | georg.brandl | 2008-02-23 16:43:48 +0100 (Sat, 23 Feb 2008) | 2 lines
#2161: Fix opcode name.
........
r60989 | andrew.kuchling | 2008-02-23 16:49:35 +0100 (Sat, 23 Feb 2008) | 2 lines
#1119331: ncurses will just call exit() if the terminal name isn't found.
Call setupterm() first so that we get a Python exception instead of just existing.
........
2008-02-23 12:23:06 -04:00
|
|
|
.. function:: siginterrupt(signalnum, flag)
|
|
|
|
|
|
|
|
Change system call restart behaviour: if *flag* is :const:`False`, system calls
|
Merged revisions 61209-61214,61217-61222,61224-61226,61233-61237 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61209 | georg.brandl | 2008-03-03 21:37:55 +0100 (Mon, 03 Mar 2008) | 2 lines
There are now sixteen isfoo functions.
........
r61210 | georg.brandl | 2008-03-03 21:39:00 +0100 (Mon, 03 Mar 2008) | 2 lines
15 -> 16, the 2nd
........
r61211 | georg.brandl | 2008-03-03 22:22:47 +0100 (Mon, 03 Mar 2008) | 2 lines
Actually import itertools.
........
r61212 | georg.brandl | 2008-03-03 22:31:50 +0100 (Mon, 03 Mar 2008) | 2 lines
Expand a bit on genexp scopes.
........
r61213 | raymond.hettinger | 2008-03-03 23:04:55 +0100 (Mon, 03 Mar 2008) | 1 line
Remove dependency on itertools -- a simple genexp suffices.
........
r61214 | raymond.hettinger | 2008-03-03 23:19:58 +0100 (Mon, 03 Mar 2008) | 1 line
Issue 2226: Callable checked for the wrong abstract method.
........
r61217 | andrew.kuchling | 2008-03-04 01:40:32 +0100 (Tue, 04 Mar 2008) | 1 line
Typo fix
........
r61218 | andrew.kuchling | 2008-03-04 02:30:10 +0100 (Tue, 04 Mar 2008) | 1 line
Grammar fix; markup fix
........
r61219 | andrew.kuchling | 2008-03-04 02:47:38 +0100 (Tue, 04 Mar 2008) | 1 line
Fix sentence fragment
........
r61220 | andrew.kuchling | 2008-03-04 02:48:26 +0100 (Tue, 04 Mar 2008) | 1 line
Typo fix
........
r61221 | andrew.kuchling | 2008-03-04 02:49:37 +0100 (Tue, 04 Mar 2008) | 1 line
Add versionadded tags
........
r61222 | andrew.kuchling | 2008-03-04 02:50:32 +0100 (Tue, 04 Mar 2008) | 1 line
Thesis night results: add various items
........
r61224 | raymond.hettinger | 2008-03-04 05:17:08 +0100 (Tue, 04 Mar 2008) | 1 line
Beef-up docs and tests for itertools. Fix-up end-case for product().
........
r61225 | georg.brandl | 2008-03-04 08:25:54 +0100 (Tue, 04 Mar 2008) | 2 lines
Fix some patch attributions.
........
r61226 | georg.brandl | 2008-03-04 08:33:30 +0100 (Tue, 04 Mar 2008) | 2 lines
#2230: document that PyArg_* leaves addresses alone on error.
........
r61233 | neal.norwitz | 2008-03-04 17:22:46 +0100 (Tue, 04 Mar 2008) | 3 lines
Close the file before trying to remove the directory so it works on Windows.
As reported by Trent Nelson on python-dev.
........
r61234 | thomas.heller | 2008-03-04 21:09:11 +0100 (Tue, 04 Mar 2008) | 9 lines
Merged changes from libffi3-branch.
The bundled libffi copy is now in sync with the recently released
libffi3.0.4 version, apart from some small changes to
Modules/_ctypes/libffi/configure.ac.
I gave up on using libffi3 files on os x.
Instead, static configuration with files from pyobjc is used.
........
r61235 | thomas.heller | 2008-03-04 21:21:42 +0100 (Tue, 04 Mar 2008) | 1 line
Try to fix the build for PY_LINUX.
........
r61236 | fred.drake | 2008-03-04 22:14:04 +0100 (Tue, 04 Mar 2008) | 2 lines
fix typo
........
r61237 | raymond.hettinger | 2008-03-04 23:29:44 +0100 (Tue, 04 Mar 2008) | 1 line
Fix refleak in chain().
........
2008-03-04 19:39:23 -04:00
|
|
|
will be restarted when interrupted by signal *signalnum*, otherwise system calls will
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60964,60966-60967,60971,60977,60979-60989 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60980 | georg.brandl | 2008-02-23 16:02:28 +0100 (Sat, 23 Feb 2008) | 2 lines
#1492: allow overriding BaseHTTPServer's content type for error messages.
........
r60982 | georg.brandl | 2008-02-23 16:06:25 +0100 (Sat, 23 Feb 2008) | 2 lines
#2165: fix test_logging failure on some machines.
........
r60983 | facundo.batista | 2008-02-23 16:07:35 +0100 (Sat, 23 Feb 2008) | 6 lines
Issue 1089358. Adds the siginterrupt() function, that is just a
wrapper around the system call with the same name. Also added
test cases, doc changes and NEWS entry. Thanks Jason and Ralf
Schmitt.
........
r60984 | georg.brandl | 2008-02-23 16:11:18 +0100 (Sat, 23 Feb 2008) | 2 lines
#2067: file.__exit__() now calls subclasses' close() method.
........
r60985 | georg.brandl | 2008-02-23 16:19:54 +0100 (Sat, 23 Feb 2008) | 2 lines
More difflib examples. Written for GHOP by Josip Dzolonga.
........
r60987 | andrew.kuchling | 2008-02-23 16:41:51 +0100 (Sat, 23 Feb 2008) | 1 line
#2072: correct documentation for .rpc_paths
........
r60988 | georg.brandl | 2008-02-23 16:43:48 +0100 (Sat, 23 Feb 2008) | 2 lines
#2161: Fix opcode name.
........
r60989 | andrew.kuchling | 2008-02-23 16:49:35 +0100 (Sat, 23 Feb 2008) | 2 lines
#1119331: ncurses will just call exit() if the terminal name isn't found.
Call setupterm() first so that we get a Python exception instead of just existing.
........
2008-02-23 12:23:06 -04:00
|
|
|
be interrupted. Returns nothing. Availability: Unix, Mac (see the man page
|
|
|
|
:manpage:`siginterrupt(3)` for further information).
|
|
|
|
|
|
|
|
Note that installing a signal handler with :func:`signal` will reset the restart
|
Merged revisions 61209-61214,61217-61222,61224-61226,61233-61237 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61209 | georg.brandl | 2008-03-03 21:37:55 +0100 (Mon, 03 Mar 2008) | 2 lines
There are now sixteen isfoo functions.
........
r61210 | georg.brandl | 2008-03-03 21:39:00 +0100 (Mon, 03 Mar 2008) | 2 lines
15 -> 16, the 2nd
........
r61211 | georg.brandl | 2008-03-03 22:22:47 +0100 (Mon, 03 Mar 2008) | 2 lines
Actually import itertools.
........
r61212 | georg.brandl | 2008-03-03 22:31:50 +0100 (Mon, 03 Mar 2008) | 2 lines
Expand a bit on genexp scopes.
........
r61213 | raymond.hettinger | 2008-03-03 23:04:55 +0100 (Mon, 03 Mar 2008) | 1 line
Remove dependency on itertools -- a simple genexp suffices.
........
r61214 | raymond.hettinger | 2008-03-03 23:19:58 +0100 (Mon, 03 Mar 2008) | 1 line
Issue 2226: Callable checked for the wrong abstract method.
........
r61217 | andrew.kuchling | 2008-03-04 01:40:32 +0100 (Tue, 04 Mar 2008) | 1 line
Typo fix
........
r61218 | andrew.kuchling | 2008-03-04 02:30:10 +0100 (Tue, 04 Mar 2008) | 1 line
Grammar fix; markup fix
........
r61219 | andrew.kuchling | 2008-03-04 02:47:38 +0100 (Tue, 04 Mar 2008) | 1 line
Fix sentence fragment
........
r61220 | andrew.kuchling | 2008-03-04 02:48:26 +0100 (Tue, 04 Mar 2008) | 1 line
Typo fix
........
r61221 | andrew.kuchling | 2008-03-04 02:49:37 +0100 (Tue, 04 Mar 2008) | 1 line
Add versionadded tags
........
r61222 | andrew.kuchling | 2008-03-04 02:50:32 +0100 (Tue, 04 Mar 2008) | 1 line
Thesis night results: add various items
........
r61224 | raymond.hettinger | 2008-03-04 05:17:08 +0100 (Tue, 04 Mar 2008) | 1 line
Beef-up docs and tests for itertools. Fix-up end-case for product().
........
r61225 | georg.brandl | 2008-03-04 08:25:54 +0100 (Tue, 04 Mar 2008) | 2 lines
Fix some patch attributions.
........
r61226 | georg.brandl | 2008-03-04 08:33:30 +0100 (Tue, 04 Mar 2008) | 2 lines
#2230: document that PyArg_* leaves addresses alone on error.
........
r61233 | neal.norwitz | 2008-03-04 17:22:46 +0100 (Tue, 04 Mar 2008) | 3 lines
Close the file before trying to remove the directory so it works on Windows.
As reported by Trent Nelson on python-dev.
........
r61234 | thomas.heller | 2008-03-04 21:09:11 +0100 (Tue, 04 Mar 2008) | 9 lines
Merged changes from libffi3-branch.
The bundled libffi copy is now in sync with the recently released
libffi3.0.4 version, apart from some small changes to
Modules/_ctypes/libffi/configure.ac.
I gave up on using libffi3 files on os x.
Instead, static configuration with files from pyobjc is used.
........
r61235 | thomas.heller | 2008-03-04 21:21:42 +0100 (Tue, 04 Mar 2008) | 1 line
Try to fix the build for PY_LINUX.
........
r61236 | fred.drake | 2008-03-04 22:14:04 +0100 (Tue, 04 Mar 2008) | 2 lines
fix typo
........
r61237 | raymond.hettinger | 2008-03-04 23:29:44 +0100 (Tue, 04 Mar 2008) | 1 line
Fix refleak in chain().
........
2008-03-04 19:39:23 -04:00
|
|
|
behaviour to interruptible by implicitly calling :cfunc:`siginterrupt` with a true *flag*
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60964,60966-60967,60971,60977,60979-60989 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60980 | georg.brandl | 2008-02-23 16:02:28 +0100 (Sat, 23 Feb 2008) | 2 lines
#1492: allow overriding BaseHTTPServer's content type for error messages.
........
r60982 | georg.brandl | 2008-02-23 16:06:25 +0100 (Sat, 23 Feb 2008) | 2 lines
#2165: fix test_logging failure on some machines.
........
r60983 | facundo.batista | 2008-02-23 16:07:35 +0100 (Sat, 23 Feb 2008) | 6 lines
Issue 1089358. Adds the siginterrupt() function, that is just a
wrapper around the system call with the same name. Also added
test cases, doc changes and NEWS entry. Thanks Jason and Ralf
Schmitt.
........
r60984 | georg.brandl | 2008-02-23 16:11:18 +0100 (Sat, 23 Feb 2008) | 2 lines
#2067: file.__exit__() now calls subclasses' close() method.
........
r60985 | georg.brandl | 2008-02-23 16:19:54 +0100 (Sat, 23 Feb 2008) | 2 lines
More difflib examples. Written for GHOP by Josip Dzolonga.
........
r60987 | andrew.kuchling | 2008-02-23 16:41:51 +0100 (Sat, 23 Feb 2008) | 1 line
#2072: correct documentation for .rpc_paths
........
r60988 | georg.brandl | 2008-02-23 16:43:48 +0100 (Sat, 23 Feb 2008) | 2 lines
#2161: Fix opcode name.
........
r60989 | andrew.kuchling | 2008-02-23 16:49:35 +0100 (Sat, 23 Feb 2008) | 2 lines
#1119331: ncurses will just call exit() if the terminal name isn't found.
Call setupterm() first so that we get a Python exception instead of just existing.
........
2008-02-23 12:23:06 -04:00
|
|
|
value for the given signal.
|
|
|
|
|
|
|
|
.. versionadded:: 2.6
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. function:: signal(signalnum, handler)
|
|
|
|
|
|
|
|
Set the handler for signal *signalnum* to the function *handler*. *handler* can
|
|
|
|
be a callable Python object taking two arguments (see below), or one of the
|
|
|
|
special values :const:`signal.SIG_IGN` or :const:`signal.SIG_DFL`. The previous
|
|
|
|
signal handler will be returned (see the description of :func:`getsignal`
|
|
|
|
above). (See the Unix man page :manpage:`signal(2)`.)
|
|
|
|
|
|
|
|
When threads are enabled, this function can only be called from the main thread;
|
|
|
|
attempting to call it from other threads will cause a :exc:`ValueError`
|
|
|
|
exception to be raised.
|
|
|
|
|
|
|
|
The *handler* is called with two arguments: the signal number and the current
|
|
|
|
stack frame (``None`` or a frame object; for a description of frame objects, see
|
|
|
|
the reference manual section on the standard type hierarchy or see the attribute
|
|
|
|
descriptions in the :mod:`inspect` module).
|
|
|
|
|
|
|
|
|
|
|
|
.. _signal-example:
|
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
|
|
|
|
Here is a minimal example program. It uses the :func:`alarm` function to limit
|
|
|
|
the time spent waiting to open a file; this is useful if the file is for a
|
|
|
|
serial device that may not be turned on, which would normally cause the
|
|
|
|
:func:`os.open` to hang indefinitely. The solution is to set a 5-second alarm
|
|
|
|
before opening the file; if the operation takes too long, the alarm signal will
|
|
|
|
be sent, and the handler raises an exception. ::
|
|
|
|
|
|
|
|
import signal, os
|
|
|
|
|
|
|
|
def handler(signum, frame):
|
2007-09-04 04:15:32 -03:00
|
|
|
print('Signal handler called with signal', signum)
|
2007-09-01 20:34:30 -03:00
|
|
|
raise IOError("Couldn't open device!")
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
# Set the signal handler and a 5-second alarm
|
|
|
|
signal.signal(signal.SIGALRM, handler)
|
|
|
|
signal.alarm(5)
|
|
|
|
|
|
|
|
# This open() may hang indefinitely
|
|
|
|
fd = os.open('/dev/ttyS0', os.O_RDWR)
|
|
|
|
|
|
|
|
signal.alarm(0) # Disable the alarm
|
|
|
|
|