cpython/Doc/library/signal.rst

369 lines
14 KiB
ReStructuredText
Raw Normal View History

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.
* 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
2009-01-03 17:18:54 -04: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
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines #4457: rewrite __import__() documentation. ........ r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line specify how things are copied ........ r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line revert unrelated change to installer script ........ r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines Add simple unittests for Request ........ r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines #1030250: correctly pass the dry_run option to the mkpath() function. ........ r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line fix incorrect example ........ r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line fix missing bracket ........ r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines #4446: document "platforms" argument for setup(). ........ r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines #4611: fix typo. ........ r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines #4578: fix has_key() usage in compiler package. ........ r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines #4568: remove limitation in varargs callback example. ........ r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines #3632: the "pyo" macro from gdbinit can now run when the GIL is released. Patch by haypo. ........ r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line fix typo ........ r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line _call_method -> _callmethod and _get_value to _getvalue ........ r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines Fix-up and clean-up docs for int.bit_length(). * Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers. * Add comments to the pure python code equivalent. * replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float). * add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to. * make one combined example with a negative input. ........ r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line copy sentence from docstring ........ r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line add headings ........ r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line beef up docstring ........ r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line remove redundant sentence ........ r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line add some recent releases to the list ........
2008-12-20 20:06:59 -04:00
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:`SIGCHLD` is to simply ignore it.
2007-08-15 11:28:22 -03:00
.. 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
':c:func:`signal`' lists the existing signals (on some systems this is
2007-08-15 11:28:22 -03:00
: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:: CTRL_C_EVENT
The signal corresponding to the CTRL+C keystroke event. This signal can
only be used with :func:`os.kill`.
Availability: Windows.
.. versionadded:: 3.2
.. data:: CTRL_BREAK_EVENT
The signal corresponding to the CTRL+BREAK keystroke event. This signal can
only be used with :func:`os.kill`.
Availability: Windows.
.. versionadded:: 3.2
2007-08-15 11:28:22 -03:00
.. data:: NSIG
One more than the number of the highest signal number.
2009-01-03 17:18:54 -04:00
.. data:: ITIMER_REAL
Decrements interval timer in real time, and delivers :const:`SIGALRM` upon
expiration.
2009-01-03 17:18:54 -04:00
.. data:: ITIMER_VIRTUAL
2009-01-03 17:18:54 -04:00
Decrements interval timer only when the process is executing, and delivers
SIGVTALRM upon expiration.
.. data:: ITIMER_PROF
2009-01-03 17:18:54 -04:00
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.
.. data:: SIG_BLOCK
A possible value for the *how* parameter to :func:`pthread_sigmask`
indicating that signals are to be blocked.
.. versionadded:: 3.3
.. data:: SIG_UNBLOCK
A possible value for the *how* parameter to :func:`pthread_sigmask`
indicating that signals are to be unblocked.
.. versionadded:: 3.3
.. data:: SIG_SETMASK
A possible value for the *how* parameter to :func:`pthread_sigmask`
indicating that the signal mask is to be replaced.
.. versionadded:: 3.3
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
2009-01-03 17:18:54 -04:00
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)`.)
See also :func:`sigwait` and :func:`sigpending`.
.. function:: pthread_kill(thread_id, signum)
Send the signal *signum* to the thread *thread_id*, another thread in the same
process as the caller. The signal is asynchronously directed to thread.
Use :func:`threading.get_ident()` or the :attr:`~threading.Thread.ident`
attribute of :attr:`threading.Thread` to get a 'thread identifier' for
*thread_id*.
If *signum* is 0, then no signal is sent, but error checking is still
performed; this can be used to check if a thread is still running.
Availability: Unix (see the man page :manpage:`pthread_kill(3)` for further
information).
See also :func:`os.kill`.
.. versionadded:: 3.3
2007-08-15 11:28:22 -03:00
.. function:: pthread_sigmask(how, mask)
Fetch and/or change the signal mask of the calling thread. The signal mask
is the set of signals whose delivery is currently blocked for the caller.
Return the old signal mask as a set of signals.
The behavior of the call is dependent on the value of *how*, as follows.
* :data:`SIG_BLOCK`: The set of blocked signals is the union of the current
set and the *mask* argument.
* :data:`SIG_UNBLOCK`: The signals in *mask* are removed from the current
set of blocked signals. It is permissible to attempt to unblock a
signal which is not blocked.
* :data:`SIG_SETMASK`: The set of blocked signals is set to the *mask*
argument.
*mask* is a set of signal numbers (e.g. {:const:`signal.SIGINT`,
:const:`signal.SIGTERM`}). Use ``range(1, signal.NSIG)`` for a full mask
including all signals.
For example, ``signal.pthread_sigmask(signal.SIG_BLOCK, [])`` reads the
signal mask of the calling thread.
Availability: Unix. See the man page :manpage:`sigprocmask(3)` and
:manpage:`pthread_sigmask(3)` for further information.
See also :func:`pause`, :func:`sigpending` and :func:`sigwait`.
.. versionadded:: 3.3
.. function:: setitimer(which, seconds[, interval])
2009-01-03 17:18:54 -04:00
Sets given interval timer (one of :const:`signal.ITIMER_REAL`,
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62127 | trent.nelson | 2008-04-03 08:39:17 -0700 (Thu, 03 Apr 2008) | 1 line Remove the building of Berkeley DB step; _bsddb44.vcproj takes care of this for us now. ........ r62136 | amaury.forgeotdarc | 2008-04-03 16:07:55 -0700 (Thu, 03 Apr 2008) | 9 lines #1733757: the interpreter would hang on shutdown, if the function set by sys.settrace calls threading.currentThread. The correction somewhat improves the code, but it was close. Many thanks to the "with" construct, which turns python code into C calls. I wonder if it is not better to sys.settrace(None) just after running the __main__ module and before finalization. ........ r62141 | jeffrey.yasskin | 2008-04-03 21:51:19 -0700 (Thu, 03 Apr 2008) | 5 lines Doh! os.read() raises an OSError, not an IOError when it's interrupted. And fix some flakiness in test_itimer_prof, which could detect that the timer had reached 0 before the signal arrived announcing that fact. ........ r62142 | fred.drake | 2008-04-03 22:41:30 -0700 (Thu, 03 Apr 2008) | 4 lines - Issue #2385: distutils.core.run_script() makes __file__ available, so the controlled environment will more closely mirror the typical script environment. This supports setup.py scripts that refer to data files. ........ r62147 | fred.drake | 2008-04-04 04:31:14 -0700 (Fri, 04 Apr 2008) | 6 lines my previous change did what I said it should not: it changed the current directory to the directory in which the setup.py script lived (which made __file__ wrong) fixed, with test that the script is run in the current directory of the caller ........ r62148 | fred.drake | 2008-04-04 04:38:51 -0700 (Fri, 04 Apr 2008) | 2 lines stupid, stupid, stupid! ........ r62150 | jeffrey.yasskin | 2008-04-04 09:48:19 -0700 (Fri, 04 Apr 2008) | 2 lines Oops again. EINTR is in errno, not signal. ........ r62158 | andrew.kuchling | 2008-04-04 19:42:20 -0700 (Fri, 04 Apr 2008) | 1 line Minor edits ........ r62159 | andrew.kuchling | 2008-04-04 19:47:07 -0700 (Fri, 04 Apr 2008) | 1 line Markup fix; explain what interval timers do; typo fix ........ r62160 | andrew.kuchling | 2008-04-04 20:38:39 -0700 (Fri, 04 Apr 2008) | 1 line Various edits ........ r62161 | neal.norwitz | 2008-04-04 21:26:31 -0700 (Fri, 04 Apr 2008) | 9 lines Prevent test_sqlite from hanging on older versions of sqlite. The problem is that when trying to do the second insert, sqlite seems to sleep for a very long time. Here is the output from strace: read(6, "SQLite format 3\0\4\0\1\1\0@ \0\0\0\1\0\0\0\0"..., 1024) = 1024 nanosleep({4294, 966296000}, <unfinished ...> I don't know which version this was fixed in, but 3.2.1 definitely fails. ........
2008-04-05 01:47:45 -03:00
:const:`signal.ITIMER_VIRTUAL` or :const:`signal.ITIMER_PROF`) specified
2009-01-03 17:18:54 -04:00
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.
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62127 | trent.nelson | 2008-04-03 08:39:17 -0700 (Thu, 03 Apr 2008) | 1 line Remove the building of Berkeley DB step; _bsddb44.vcproj takes care of this for us now. ........ r62136 | amaury.forgeotdarc | 2008-04-03 16:07:55 -0700 (Thu, 03 Apr 2008) | 9 lines #1733757: the interpreter would hang on shutdown, if the function set by sys.settrace calls threading.currentThread. The correction somewhat improves the code, but it was close. Many thanks to the "with" construct, which turns python code into C calls. I wonder if it is not better to sys.settrace(None) just after running the __main__ module and before finalization. ........ r62141 | jeffrey.yasskin | 2008-04-03 21:51:19 -0700 (Thu, 03 Apr 2008) | 5 lines Doh! os.read() raises an OSError, not an IOError when it's interrupted. And fix some flakiness in test_itimer_prof, which could detect that the timer had reached 0 before the signal arrived announcing that fact. ........ r62142 | fred.drake | 2008-04-03 22:41:30 -0700 (Thu, 03 Apr 2008) | 4 lines - Issue #2385: distutils.core.run_script() makes __file__ available, so the controlled environment will more closely mirror the typical script environment. This supports setup.py scripts that refer to data files. ........ r62147 | fred.drake | 2008-04-04 04:31:14 -0700 (Fri, 04 Apr 2008) | 6 lines my previous change did what I said it should not: it changed the current directory to the directory in which the setup.py script lived (which made __file__ wrong) fixed, with test that the script is run in the current directory of the caller ........ r62148 | fred.drake | 2008-04-04 04:38:51 -0700 (Fri, 04 Apr 2008) | 2 lines stupid, stupid, stupid! ........ r62150 | jeffrey.yasskin | 2008-04-04 09:48:19 -0700 (Fri, 04 Apr 2008) | 2 lines Oops again. EINTR is in errno, not signal. ........ r62158 | andrew.kuchling | 2008-04-04 19:42:20 -0700 (Fri, 04 Apr 2008) | 1 line Minor edits ........ r62159 | andrew.kuchling | 2008-04-04 19:47:07 -0700 (Fri, 04 Apr 2008) | 1 line Markup fix; explain what interval timers do; typo fix ........ r62160 | andrew.kuchling | 2008-04-04 20:38:39 -0700 (Fri, 04 Apr 2008) | 1 line Various edits ........ r62161 | neal.norwitz | 2008-04-04 21:26:31 -0700 (Fri, 04 Apr 2008) | 9 lines Prevent test_sqlite from hanging on older versions of sqlite. The problem is that when trying to do the second insert, sqlite seems to sleep for a very long time. Here is the output from strace: read(6, "SQLite format 3\0\4\0\1\1\0@ \0\0\0\1\0\0\0\0"..., 1024) = 1024 nanosleep({4294, 966296000}, <unfinished ...> I don't know which version this was fixed in, but 3.2.1 definitely fails. ........
2008-04-05 01:47:45 -03:00
When an interval timer fires, a signal is sent to the process.
2009-01-03 17:18:54 -04:00
The signal sent is dependent on the timer being used;
:const:`signal.ITIMER_REAL` will deliver :const:`SIGALRM`,
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62127 | trent.nelson | 2008-04-03 08:39:17 -0700 (Thu, 03 Apr 2008) | 1 line Remove the building of Berkeley DB step; _bsddb44.vcproj takes care of this for us now. ........ r62136 | amaury.forgeotdarc | 2008-04-03 16:07:55 -0700 (Thu, 03 Apr 2008) | 9 lines #1733757: the interpreter would hang on shutdown, if the function set by sys.settrace calls threading.currentThread. The correction somewhat improves the code, but it was close. Many thanks to the "with" construct, which turns python code into C calls. I wonder if it is not better to sys.settrace(None) just after running the __main__ module and before finalization. ........ r62141 | jeffrey.yasskin | 2008-04-03 21:51:19 -0700 (Thu, 03 Apr 2008) | 5 lines Doh! os.read() raises an OSError, not an IOError when it's interrupted. And fix some flakiness in test_itimer_prof, which could detect that the timer had reached 0 before the signal arrived announcing that fact. ........ r62142 | fred.drake | 2008-04-03 22:41:30 -0700 (Thu, 03 Apr 2008) | 4 lines - Issue #2385: distutils.core.run_script() makes __file__ available, so the controlled environment will more closely mirror the typical script environment. This supports setup.py scripts that refer to data files. ........ r62147 | fred.drake | 2008-04-04 04:31:14 -0700 (Fri, 04 Apr 2008) | 6 lines my previous change did what I said it should not: it changed the current directory to the directory in which the setup.py script lived (which made __file__ wrong) fixed, with test that the script is run in the current directory of the caller ........ r62148 | fred.drake | 2008-04-04 04:38:51 -0700 (Fri, 04 Apr 2008) | 2 lines stupid, stupid, stupid! ........ r62150 | jeffrey.yasskin | 2008-04-04 09:48:19 -0700 (Fri, 04 Apr 2008) | 2 lines Oops again. EINTR is in errno, not signal. ........ r62158 | andrew.kuchling | 2008-04-04 19:42:20 -0700 (Fri, 04 Apr 2008) | 1 line Minor edits ........ r62159 | andrew.kuchling | 2008-04-04 19:47:07 -0700 (Fri, 04 Apr 2008) | 1 line Markup fix; explain what interval timers do; typo fix ........ r62160 | andrew.kuchling | 2008-04-04 20:38:39 -0700 (Fri, 04 Apr 2008) | 1 line Various edits ........ r62161 | neal.norwitz | 2008-04-04 21:26:31 -0700 (Fri, 04 Apr 2008) | 9 lines Prevent test_sqlite from hanging on older versions of sqlite. The problem is that when trying to do the second insert, sqlite seems to sleep for a very long time. Here is the output from strace: read(6, "SQLite format 3\0\4\0\1\1\0@ \0\0\0\1\0\0\0\0"..., 1024) = 1024 nanosleep({4294, 966296000}, <unfinished ...> I don't know which version this was fixed in, but 3.2.1 definitely fails. ........
2008-04-05 01:47:45 -03:00
:const:`signal.ITIMER_VIRTUAL` sends :const:`SIGVTALRM`,
and :const:`signal.ITIMER_PROF` will deliver :const:`SIGPROF`.
The old values are returned as a tuple: (delay, interval).
Merged revisions 75365,75394,75402-75403,75418,75459,75484,75592-75596,75600,75602-75607,75610-75613,75616-75617,75623,75627,75640,75647,75696,75795 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75365 | georg.brandl | 2009-10-11 22:16:16 +0200 (So, 11 Okt 2009) | 1 line Fix broken links found by "make linkcheck". scipy.org seems to be done right now, so I could not verify links going there. ........ r75394 | georg.brandl | 2009-10-13 20:10:59 +0200 (Di, 13 Okt 2009) | 1 line Fix markup. ........ r75402 | georg.brandl | 2009-10-14 17:51:48 +0200 (Mi, 14 Okt 2009) | 1 line #7125: fix typo. ........ r75403 | georg.brandl | 2009-10-14 17:57:46 +0200 (Mi, 14 Okt 2009) | 1 line #7126: os.environ changes *do* take effect in subprocesses started with os.system(). ........ r75418 | georg.brandl | 2009-10-14 20:48:32 +0200 (Mi, 14 Okt 2009) | 1 line #7116: str.join() takes an iterable. ........ r75459 | georg.brandl | 2009-10-17 10:57:43 +0200 (Sa, 17 Okt 2009) | 1 line Fix refleaks in _ctypes PyCSimpleType_New, which fixes the refleak seen in test___all__. ........ r75484 | georg.brandl | 2009-10-18 09:58:12 +0200 (So, 18 Okt 2009) | 1 line Fix missing word. ........ r75592 | georg.brandl | 2009-10-22 09:05:48 +0200 (Do, 22 Okt 2009) | 1 line Fix punctuation. ........ r75593 | georg.brandl | 2009-10-22 09:06:49 +0200 (Do, 22 Okt 2009) | 1 line Revert unintended change. ........ r75594 | georg.brandl | 2009-10-22 09:56:02 +0200 (Do, 22 Okt 2009) | 1 line Fix markup. ........ r75595 | georg.brandl | 2009-10-22 09:56:56 +0200 (Do, 22 Okt 2009) | 1 line Fix duplicate target. ........ r75596 | georg.brandl | 2009-10-22 10:05:04 +0200 (Do, 22 Okt 2009) | 1 line Add a new directive marking up implementation details and start using it. ........ r75600 | georg.brandl | 2009-10-22 13:01:46 +0200 (Do, 22 Okt 2009) | 1 line Make it more robust. ........ r75602 | georg.brandl | 2009-10-22 13:28:06 +0200 (Do, 22 Okt 2009) | 1 line Document new directive. ........ r75603 | georg.brandl | 2009-10-22 13:28:23 +0200 (Do, 22 Okt 2009) | 1 line Allow short form with text as argument. ........ r75604 | georg.brandl | 2009-10-22 13:36:50 +0200 (Do, 22 Okt 2009) | 1 line Fix stylesheet for multi-paragraph impl-details. ........ r75605 | georg.brandl | 2009-10-22 13:48:10 +0200 (Do, 22 Okt 2009) | 1 line Use "impl-detail" directive where applicable. ........ r75606 | georg.brandl | 2009-10-22 17:00:06 +0200 (Do, 22 Okt 2009) | 1 line #6324: membership test tries iteration via __iter__. ........ r75607 | georg.brandl | 2009-10-22 17:04:09 +0200 (Do, 22 Okt 2009) | 1 line #7088: document new functions in signal as Unix-only. ........ r75610 | georg.brandl | 2009-10-22 17:27:24 +0200 (Do, 22 Okt 2009) | 1 line Reorder __slots__ fine print and add a clarification. ........ r75611 | georg.brandl | 2009-10-22 17:42:32 +0200 (Do, 22 Okt 2009) | 1 line #7035: improve docs of the various <method>_errors() functions, and give them docstrings. ........ r75612 | georg.brandl | 2009-10-22 17:52:15 +0200 (Do, 22 Okt 2009) | 1 line #7156: document curses as Unix-only. ........ r75613 | georg.brandl | 2009-10-22 17:54:35 +0200 (Do, 22 Okt 2009) | 1 line #6977: getopt does not support optional option arguments. ........ r75616 | georg.brandl | 2009-10-22 18:17:05 +0200 (Do, 22 Okt 2009) | 1 line Add proper references. ........ r75617 | georg.brandl | 2009-10-22 18:20:55 +0200 (Do, 22 Okt 2009) | 1 line Make printout margin important. ........ r75623 | georg.brandl | 2009-10-23 10:14:44 +0200 (Fr, 23 Okt 2009) | 1 line #7188: fix optionxform() docs. ........ r75627 | fred.drake | 2009-10-23 15:04:51 +0200 (Fr, 23 Okt 2009) | 2 lines add further note about what's passed to optionxform ........ r75640 | neil.schemenauer | 2009-10-23 21:58:17 +0200 (Fr, 23 Okt 2009) | 2 lines Improve some docstrings in the 'warnings' module. ........ r75647 | georg.brandl | 2009-10-24 12:04:19 +0200 (Sa, 24 Okt 2009) | 1 line Fix markup. ........ r75696 | georg.brandl | 2009-10-25 21:25:43 +0100 (So, 25 Okt 2009) | 1 line Fix a demo. ........ r75795 | georg.brandl | 2009-10-27 16:10:22 +0100 (Di, 27 Okt 2009) | 1 line Fix a strange mis-edit. ........
2009-10-27 12:28:25 -03:00
Attempting to pass an invalid interval timer will cause an
:exc:`ItimerError`. Availability: Unix.
.. function:: getitimer(which)
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62127 | trent.nelson | 2008-04-03 08:39:17 -0700 (Thu, 03 Apr 2008) | 1 line Remove the building of Berkeley DB step; _bsddb44.vcproj takes care of this for us now. ........ r62136 | amaury.forgeotdarc | 2008-04-03 16:07:55 -0700 (Thu, 03 Apr 2008) | 9 lines #1733757: the interpreter would hang on shutdown, if the function set by sys.settrace calls threading.currentThread. The correction somewhat improves the code, but it was close. Many thanks to the "with" construct, which turns python code into C calls. I wonder if it is not better to sys.settrace(None) just after running the __main__ module and before finalization. ........ r62141 | jeffrey.yasskin | 2008-04-03 21:51:19 -0700 (Thu, 03 Apr 2008) | 5 lines Doh! os.read() raises an OSError, not an IOError when it's interrupted. And fix some flakiness in test_itimer_prof, which could detect that the timer had reached 0 before the signal arrived announcing that fact. ........ r62142 | fred.drake | 2008-04-03 22:41:30 -0700 (Thu, 03 Apr 2008) | 4 lines - Issue #2385: distutils.core.run_script() makes __file__ available, so the controlled environment will more closely mirror the typical script environment. This supports setup.py scripts that refer to data files. ........ r62147 | fred.drake | 2008-04-04 04:31:14 -0700 (Fri, 04 Apr 2008) | 6 lines my previous change did what I said it should not: it changed the current directory to the directory in which the setup.py script lived (which made __file__ wrong) fixed, with test that the script is run in the current directory of the caller ........ r62148 | fred.drake | 2008-04-04 04:38:51 -0700 (Fri, 04 Apr 2008) | 2 lines stupid, stupid, stupid! ........ r62150 | jeffrey.yasskin | 2008-04-04 09:48:19 -0700 (Fri, 04 Apr 2008) | 2 lines Oops again. EINTR is in errno, not signal. ........ r62158 | andrew.kuchling | 2008-04-04 19:42:20 -0700 (Fri, 04 Apr 2008) | 1 line Minor edits ........ r62159 | andrew.kuchling | 2008-04-04 19:47:07 -0700 (Fri, 04 Apr 2008) | 1 line Markup fix; explain what interval timers do; typo fix ........ r62160 | andrew.kuchling | 2008-04-04 20:38:39 -0700 (Fri, 04 Apr 2008) | 1 line Various edits ........ r62161 | neal.norwitz | 2008-04-04 21:26:31 -0700 (Fri, 04 Apr 2008) | 9 lines Prevent test_sqlite from hanging on older versions of sqlite. The problem is that when trying to do the second insert, sqlite seems to sleep for a very long time. Here is the output from strace: read(6, "SQLite format 3\0\4\0\1\1\0@ \0\0\0\1\0\0\0\0"..., 1024) = 1024 nanosleep({4294, 966296000}, <unfinished ...> I don't know which version this was fixed in, but 3.2.1 definitely fails. ........
2008-04-05 01:47:45 -03:00
Returns current value of a given interval timer specified by *which*.
Merged revisions 75365,75394,75402-75403,75418,75459,75484,75592-75596,75600,75602-75607,75610-75613,75616-75617,75623,75627,75640,75647,75696,75795 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75365 | georg.brandl | 2009-10-11 22:16:16 +0200 (So, 11 Okt 2009) | 1 line Fix broken links found by "make linkcheck". scipy.org seems to be done right now, so I could not verify links going there. ........ r75394 | georg.brandl | 2009-10-13 20:10:59 +0200 (Di, 13 Okt 2009) | 1 line Fix markup. ........ r75402 | georg.brandl | 2009-10-14 17:51:48 +0200 (Mi, 14 Okt 2009) | 1 line #7125: fix typo. ........ r75403 | georg.brandl | 2009-10-14 17:57:46 +0200 (Mi, 14 Okt 2009) | 1 line #7126: os.environ changes *do* take effect in subprocesses started with os.system(). ........ r75418 | georg.brandl | 2009-10-14 20:48:32 +0200 (Mi, 14 Okt 2009) | 1 line #7116: str.join() takes an iterable. ........ r75459 | georg.brandl | 2009-10-17 10:57:43 +0200 (Sa, 17 Okt 2009) | 1 line Fix refleaks in _ctypes PyCSimpleType_New, which fixes the refleak seen in test___all__. ........ r75484 | georg.brandl | 2009-10-18 09:58:12 +0200 (So, 18 Okt 2009) | 1 line Fix missing word. ........ r75592 | georg.brandl | 2009-10-22 09:05:48 +0200 (Do, 22 Okt 2009) | 1 line Fix punctuation. ........ r75593 | georg.brandl | 2009-10-22 09:06:49 +0200 (Do, 22 Okt 2009) | 1 line Revert unintended change. ........ r75594 | georg.brandl | 2009-10-22 09:56:02 +0200 (Do, 22 Okt 2009) | 1 line Fix markup. ........ r75595 | georg.brandl | 2009-10-22 09:56:56 +0200 (Do, 22 Okt 2009) | 1 line Fix duplicate target. ........ r75596 | georg.brandl | 2009-10-22 10:05:04 +0200 (Do, 22 Okt 2009) | 1 line Add a new directive marking up implementation details and start using it. ........ r75600 | georg.brandl | 2009-10-22 13:01:46 +0200 (Do, 22 Okt 2009) | 1 line Make it more robust. ........ r75602 | georg.brandl | 2009-10-22 13:28:06 +0200 (Do, 22 Okt 2009) | 1 line Document new directive. ........ r75603 | georg.brandl | 2009-10-22 13:28:23 +0200 (Do, 22 Okt 2009) | 1 line Allow short form with text as argument. ........ r75604 | georg.brandl | 2009-10-22 13:36:50 +0200 (Do, 22 Okt 2009) | 1 line Fix stylesheet for multi-paragraph impl-details. ........ r75605 | georg.brandl | 2009-10-22 13:48:10 +0200 (Do, 22 Okt 2009) | 1 line Use "impl-detail" directive where applicable. ........ r75606 | georg.brandl | 2009-10-22 17:00:06 +0200 (Do, 22 Okt 2009) | 1 line #6324: membership test tries iteration via __iter__. ........ r75607 | georg.brandl | 2009-10-22 17:04:09 +0200 (Do, 22 Okt 2009) | 1 line #7088: document new functions in signal as Unix-only. ........ r75610 | georg.brandl | 2009-10-22 17:27:24 +0200 (Do, 22 Okt 2009) | 1 line Reorder __slots__ fine print and add a clarification. ........ r75611 | georg.brandl | 2009-10-22 17:42:32 +0200 (Do, 22 Okt 2009) | 1 line #7035: improve docs of the various <method>_errors() functions, and give them docstrings. ........ r75612 | georg.brandl | 2009-10-22 17:52:15 +0200 (Do, 22 Okt 2009) | 1 line #7156: document curses as Unix-only. ........ r75613 | georg.brandl | 2009-10-22 17:54:35 +0200 (Do, 22 Okt 2009) | 1 line #6977: getopt does not support optional option arguments. ........ r75616 | georg.brandl | 2009-10-22 18:17:05 +0200 (Do, 22 Okt 2009) | 1 line Add proper references. ........ r75617 | georg.brandl | 2009-10-22 18:20:55 +0200 (Do, 22 Okt 2009) | 1 line Make printout margin important. ........ r75623 | georg.brandl | 2009-10-23 10:14:44 +0200 (Fr, 23 Okt 2009) | 1 line #7188: fix optionxform() docs. ........ r75627 | fred.drake | 2009-10-23 15:04:51 +0200 (Fr, 23 Okt 2009) | 2 lines add further note about what's passed to optionxform ........ r75640 | neil.schemenauer | 2009-10-23 21:58:17 +0200 (Fr, 23 Okt 2009) | 2 lines Improve some docstrings in the 'warnings' module. ........ r75647 | georg.brandl | 2009-10-24 12:04:19 +0200 (Sa, 24 Okt 2009) | 1 line Fix markup. ........ r75696 | georg.brandl | 2009-10-25 21:25:43 +0100 (So, 25 Okt 2009) | 1 line Fix a demo. ........ r75795 | georg.brandl | 2009-10-27 16:10:22 +0100 (Di, 27 Okt 2009) | 1 line Fix a strange mis-edit. ........
2009-10-27 12:28:25 -03:00
Availability: Unix.
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 file descriptor to *fd*. When a signal is received, the
signal number is written as a single byte into the fd. This can be used by
a library to wakeup a poll or select call, allowing the signal to be fully
processed.
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
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.
Use for example ``struct.unpack('%uB' % len(data), data)`` to decode the
signal numbers list.
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
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 will be restarted when interrupted by signal *signalnum*, otherwise
Merged revisions 75365,75394,75402-75403,75418,75459,75484,75592-75596,75600,75602-75607,75610-75613,75616-75617,75623,75627,75640,75647,75696,75795 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75365 | georg.brandl | 2009-10-11 22:16:16 +0200 (So, 11 Okt 2009) | 1 line Fix broken links found by "make linkcheck". scipy.org seems to be done right now, so I could not verify links going there. ........ r75394 | georg.brandl | 2009-10-13 20:10:59 +0200 (Di, 13 Okt 2009) | 1 line Fix markup. ........ r75402 | georg.brandl | 2009-10-14 17:51:48 +0200 (Mi, 14 Okt 2009) | 1 line #7125: fix typo. ........ r75403 | georg.brandl | 2009-10-14 17:57:46 +0200 (Mi, 14 Okt 2009) | 1 line #7126: os.environ changes *do* take effect in subprocesses started with os.system(). ........ r75418 | georg.brandl | 2009-10-14 20:48:32 +0200 (Mi, 14 Okt 2009) | 1 line #7116: str.join() takes an iterable. ........ r75459 | georg.brandl | 2009-10-17 10:57:43 +0200 (Sa, 17 Okt 2009) | 1 line Fix refleaks in _ctypes PyCSimpleType_New, which fixes the refleak seen in test___all__. ........ r75484 | georg.brandl | 2009-10-18 09:58:12 +0200 (So, 18 Okt 2009) | 1 line Fix missing word. ........ r75592 | georg.brandl | 2009-10-22 09:05:48 +0200 (Do, 22 Okt 2009) | 1 line Fix punctuation. ........ r75593 | georg.brandl | 2009-10-22 09:06:49 +0200 (Do, 22 Okt 2009) | 1 line Revert unintended change. ........ r75594 | georg.brandl | 2009-10-22 09:56:02 +0200 (Do, 22 Okt 2009) | 1 line Fix markup. ........ r75595 | georg.brandl | 2009-10-22 09:56:56 +0200 (Do, 22 Okt 2009) | 1 line Fix duplicate target. ........ r75596 | georg.brandl | 2009-10-22 10:05:04 +0200 (Do, 22 Okt 2009) | 1 line Add a new directive marking up implementation details and start using it. ........ r75600 | georg.brandl | 2009-10-22 13:01:46 +0200 (Do, 22 Okt 2009) | 1 line Make it more robust. ........ r75602 | georg.brandl | 2009-10-22 13:28:06 +0200 (Do, 22 Okt 2009) | 1 line Document new directive. ........ r75603 | georg.brandl | 2009-10-22 13:28:23 +0200 (Do, 22 Okt 2009) | 1 line Allow short form with text as argument. ........ r75604 | georg.brandl | 2009-10-22 13:36:50 +0200 (Do, 22 Okt 2009) | 1 line Fix stylesheet for multi-paragraph impl-details. ........ r75605 | georg.brandl | 2009-10-22 13:48:10 +0200 (Do, 22 Okt 2009) | 1 line Use "impl-detail" directive where applicable. ........ r75606 | georg.brandl | 2009-10-22 17:00:06 +0200 (Do, 22 Okt 2009) | 1 line #6324: membership test tries iteration via __iter__. ........ r75607 | georg.brandl | 2009-10-22 17:04:09 +0200 (Do, 22 Okt 2009) | 1 line #7088: document new functions in signal as Unix-only. ........ r75610 | georg.brandl | 2009-10-22 17:27:24 +0200 (Do, 22 Okt 2009) | 1 line Reorder __slots__ fine print and add a clarification. ........ r75611 | georg.brandl | 2009-10-22 17:42:32 +0200 (Do, 22 Okt 2009) | 1 line #7035: improve docs of the various <method>_errors() functions, and give them docstrings. ........ r75612 | georg.brandl | 2009-10-22 17:52:15 +0200 (Do, 22 Okt 2009) | 1 line #7156: document curses as Unix-only. ........ r75613 | georg.brandl | 2009-10-22 17:54:35 +0200 (Do, 22 Okt 2009) | 1 line #6977: getopt does not support optional option arguments. ........ r75616 | georg.brandl | 2009-10-22 18:17:05 +0200 (Do, 22 Okt 2009) | 1 line Add proper references. ........ r75617 | georg.brandl | 2009-10-22 18:20:55 +0200 (Do, 22 Okt 2009) | 1 line Make printout margin important. ........ r75623 | georg.brandl | 2009-10-23 10:14:44 +0200 (Fr, 23 Okt 2009) | 1 line #7188: fix optionxform() docs. ........ r75627 | fred.drake | 2009-10-23 15:04:51 +0200 (Fr, 23 Okt 2009) | 2 lines add further note about what's passed to optionxform ........ r75640 | neil.schemenauer | 2009-10-23 21:58:17 +0200 (Fr, 23 Okt 2009) | 2 lines Improve some docstrings in the 'warnings' module. ........ r75647 | georg.brandl | 2009-10-24 12:04:19 +0200 (Sa, 24 Okt 2009) | 1 line Fix markup. ........ r75696 | georg.brandl | 2009-10-25 21:25:43 +0100 (So, 25 Okt 2009) | 1 line Fix a demo. ........ r75795 | georg.brandl | 2009-10-27 16:10:22 +0100 (Di, 27 Okt 2009) | 1 line Fix a strange mis-edit. ........
2009-10-27 12:28:25 -03:00
system calls will be interrupted. Returns nothing. Availability: Unix (see
the man page :manpage:`siginterrupt(3)` for further information).
2009-01-03 17:18:54 -04:00
Note that installing a signal handler with :func:`signal` will reset the
restart behaviour to interruptible by implicitly calling
:c:func:`siginterrupt` with a true *flag* value for the given signal.
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
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
Merged revisions 74542,74544-74548,74550,74554-74555,74578,74588,74590,74603,74616-74618,74621 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74542 | georg.brandl | 2009-08-23 23:28:56 +0200 (So, 23 Aug 2009) | 1 line Restore alphabetic order. ........ r74544 | georg.brandl | 2009-08-24 19:12:30 +0200 (Mo, 24 Aug 2009) | 1 line #6775: fix python.org URLs in README. ........ r74545 | georg.brandl | 2009-08-24 19:14:29 +0200 (Mo, 24 Aug 2009) | 1 line #6772: mention utf-8 as utf8 alias. ........ r74546 | georg.brandl | 2009-08-24 19:20:40 +0200 (Mo, 24 Aug 2009) | 1 line #6725: spell "namespace" consistently. ........ r74547 | georg.brandl | 2009-08-24 19:22:05 +0200 (Mo, 24 Aug 2009) | 1 line #6718: fix example. ........ r74548 | georg.brandl | 2009-08-24 19:24:27 +0200 (Mo, 24 Aug 2009) | 1 line #6677: mention "deleting" as an alias for removing files. ........ r74550 | georg.brandl | 2009-08-24 19:48:40 +0200 (Mo, 24 Aug 2009) | 1 line #6677: note that rmdir only removes empty directories. ........ r74554 | georg.brandl | 2009-08-27 20:59:02 +0200 (Do, 27 Aug 2009) | 1 line Typo fix. ........ r74555 | georg.brandl | 2009-08-27 21:02:43 +0200 (Do, 27 Aug 2009) | 1 line #6787: reference fix. ........ r74578 | tarek.ziade | 2009-08-29 15:33:21 +0200 (Sa, 29 Aug 2009) | 1 line fixed #6801: symmetric_difference_update also accepts pipe ........ r74588 | georg.brandl | 2009-08-30 10:35:01 +0200 (So, 30 Aug 2009) | 1 line #6803: fix old name. ........ r74590 | georg.brandl | 2009-08-30 13:51:53 +0200 (So, 30 Aug 2009) | 1 line #6801: fix copy-paste oversight. ........ r74603 | georg.brandl | 2009-08-31 08:38:29 +0200 (Mo, 31 Aug 2009) | 1 line other -> others where multiple arguments are accepted. ........ r74616 | georg.brandl | 2009-09-01 09:46:26 +0200 (Di, 01 Sep 2009) | 1 line #6808: clarification. ........ r74617 | georg.brandl | 2009-09-01 09:53:37 +0200 (Di, 01 Sep 2009) | 1 line #6765: hint that log(x, base) is not very sophisticated. ........ r74618 | georg.brandl | 2009-09-01 10:00:47 +0200 (Di, 01 Sep 2009) | 1 line #6810: add a link to the section about frame objects instead of just a description where to find it. ........ r74621 | georg.brandl | 2009-09-01 10:06:03 +0200 (Di, 01 Sep 2009) | 1 line #6638: fix wrong parameter name and markup a class. ........
2009-09-01 05:11:14 -03:00
stack frame (``None`` or a frame object; for a description of frame objects,
see the :ref:`description in the type hierarchy <frame-objects>` or see the
attribute descriptions in the :mod:`inspect` module).
2007-08-15 11:28:22 -03:00
On Windows, :func:`signal` can only be called with :const:`SIGABRT`,
:const:`SIGFPE`, :const:`SIGILL`, :const:`SIGINT`, :const:`SIGSEGV`, or
:const:`SIGTERM`. A :exc:`ValueError` will be raised in any other case.
2007-08-15 11:28:22 -03:00
.. function:: sigpending()
Examine the set of signals that are pending for delivery to the calling
thread (i.e., the signals which have been raised while blocked). Return the
set of the pending signals.
Availability: Unix (see the man page :manpage:`sigpending(2)` for further
information).
See also :func:`pause`, :func:`pthread_sigmask` and :func:`sigwait`.
.. versionadded:: 3.3
.. function:: sigwait(sigset)
Suspend execution of the calling thread until the delivery of one of the
signals specified in the signal set *sigset*. The function accepts the signal
(removes it from the pending list of signals), and returns the signal number.
Availability: Unix (see the man page :manpage:`sigwait(3)` for further
information).
See also :func:`pause`, :func:`pthread_sigmask` and :func:`sigpending`.
.. versionadded:: 3.3
2007-08-15 11:28:22 -03:00
.. _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):
print('Signal handler called with signal', signum)
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
2009-01-03 17:18:54 -04:00
fd = os.open('/dev/ttyS0', os.O_RDWR)
2007-08-15 11:28:22 -03:00
signal.alarm(0) # Disable the alarm