Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43ed43b

Browse files
author
Michael W. Hudson
committed
Take out my (long since disabled) POSIX signal mask handling code.
I'm not going to have the time or energy to get this working x-platform -- anyone who does is welcome to the code!
1 parent 94afd30 commit 43ed43b

5 files changed

Lines changed: 6 additions & 289 deletions

File tree

Doc/lib/libsignal.tex

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ \section{\module{signal} ---
1717
the handler for \constant{SIGCHLD}, which follows the underlying
1818
implementation.
1919

20+
\item
21+
There is no way to ``block'' signals temporarily from critical
22+
sections (since this is not supported by all \UNIX{} flavors).
23+
2024
\item
2125
Although Python signal handlers are called asynchronously as far as
2226
the Python user is concerned, they can only occur between the
@@ -88,16 +92,6 @@ \section{\module{signal} ---
8892
One more than the number of the highest signal number.
8993
\end{datadesc}
9094

91-
\begin{datadesc}{SIG_BLOCK}
92-
\end{datadesc}
93-
\begin{datadesc}{SIG_UNBLOCK}
94-
\end{datadesc}
95-
\begin{datadesc}{SIG_SETMASK}
96-
These constants are for use as the first parameter of the
97-
\function{sigprocmask} function described below.
98-
\end{datadesc}
99-
100-
10195
The \module{signal} module defines the following functions:
10296

10397
\begin{funcdesc}{alarm}{time}
@@ -150,46 +144,6 @@ \section{\module{signal} ---
150144
\obindex{frame}
151145
\end{funcdesc}
152146

153-
The following functions are supported if your platform does. Most
154-
modern \UNIX-alikes now do.
155-
156-
\begin{funcdesc}{sigpending}{}
157-
Return the set of pending signals, i.e. a list containing the
158-
numbers of those signals that have been raised while blocked.
159-
\versionadded{2.3}
160-
\end{funcdesc}
161-
162-
\begin{funcdesc}{sigprocmask}{how, sigset}
163-
Change the list of currently blocked signals. The parameter
164-
\var{how} should be one of \constant{SIG_BLOCK},
165-
\constant{SIG_UNBLOCK} or \constant{SIG_SETMASK} and \var{sigset}
166-
should be a sequence of signal numbers. The behaviour of the call
167-
depends on the value of \var{how}:
168-
169-
\begin{tableii}{l|l}{textrm}{Value of \var{how}}{Behaviour of call}
170-
\lineii{\constant{SIG_BLOCK}}
171-
{The set of blocked signals is the union of the current set
172-
and \var{sigset}.}
173-
\lineii{\constant{SIG_UNBLOCK}}
174-
{The signals in \var{sigset} are removed from the current
175-
set of blocked signals. It is legal to attempt to unblock
176-
a signal which is not blocked.}
177-
\lineii{\constant{SIG_SETMASK}}
178-
{The set of blocked signals is set to the \var{sigset}.}
179-
\end{tableii}
180-
181-
A list contating the numbers of the previously blocked signals is
182-
returned.
183-
\versionadded{2.3}
184-
\end{funcdesc}
185-
186-
\begin{funcdesc}{sigsuspend}{sigset}
187-
Temporarily replace the signal mask with \var{sigset} (which should
188-
be a sequnce of signal numbers) and suspend the process until a
189-
signal is received.
190-
\versionadded{2.3}
191-
\end{funcdesc}
192-
193147
\subsection{Example}
194148
\nodename{Signal Example}
195149

Doc/whatsnew/whatsnew23.tex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,10 +1485,8 @@ \section{New, Improved, and Deprecated Modules}
14851485
location.
14861486

14871487
\item Support for more advanced POSIX signal handling was added
1488-
to the \module{signal} module by adding the \function{sigpending},
1489-
\function{sigprocmask} and \function{sigsuspend} functions where supported
1490-
by the platform. These functions make it possible to avoid some previously
1491-
unavoidable race conditions with signal handling.
1488+
to the \module{signal} but then removed again as it proved impossible
1489+
to make it work reliably across platforms.
14921490

14931491
\item The \module{socket} module now supports timeouts. You
14941492
can call the \method{settimeout(\var{t})} method on a socket object to

Lib/test/test_signal.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -64,64 +64,3 @@ def handlerB(*args):
6464
if verbose:
6565
print "KeyboardInterrupt (assume the alarm() went off)"
6666

67-
68-
if hasattr(signal, "sigprocmask"):
69-
class HupDelivered(Exception):
70-
pass
71-
def hup(signum, frame):
72-
raise HupDelivered
73-
def hup2(signum, frame):
74-
signal.signal(signal.SIGHUP, hup)
75-
return
76-
signal.signal(signal.SIGHUP, hup)
77-
78-
if verbose:
79-
print "blocking SIGHUP"
80-
81-
defaultmask = signal.sigprocmask(signal.SIG_BLOCK, [signal.SIGHUP])
82-
83-
if verbose:
84-
print "sending SIGHUP"
85-
86-
try:
87-
os.kill(pid, signal.SIGHUP)
88-
except HupDelivered:
89-
raise TestFailed, "HUP not blocked"
90-
91-
if signal.SIGHUP not in signal.sigpending():
92-
raise TestFailed, "HUP not pending"
93-
94-
if verbose:
95-
print "unblocking SIGHUP"
96-
97-
try:
98-
signal.sigprocmask(signal.SIG_UNBLOCK, [signal.SIGHUP])
99-
except HupDelivered:
100-
pass
101-
else:
102-
raise TestFailed, "HUP not delivered"
103-
104-
if verbose:
105-
print "testing sigsuspend"
106-
107-
signal.sigprocmask(signal.SIG_BLOCK, [signal.SIGHUP])
108-
signal.signal(signal.SIGHUP, hup2)
109-
110-
if not os.fork():
111-
time.sleep(2)
112-
os.kill(pid, signal.SIGHUP)
113-
time.sleep(2)
114-
os.kill(pid, signal.SIGHUP)
115-
os._exit(0)
116-
else:
117-
try:
118-
signal.sigsuspend(defaultmask)
119-
except:
120-
raise TestFailed, "sigsuspend erroneously raised"
121-
122-
try:
123-
signal.sigsuspend(defaultmask)
124-
except HupDelivered:
125-
pass
126-
else:
127-
raise TestFailed, "sigsupsend didn't raise"

Misc/NEWS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,9 +982,6 @@ Extension modules
982982
of sizeof(int)!=sizeof(long)!=sizeof(void*) is delayed until dl.open
983983
is called.
984984

985-
- signal.sigpending, signal.sigprocmask and signal.sigsuspend have
986-
been added where available.
987-
988985
- The sys module acquired a new attribute, api_version, which evaluates
989986
to the value of the PYTHON_API_VERSION macro with which the
990987
interpreter was compiled.

Modules/signalmodule.c

Lines changed: 0 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -269,153 +269,6 @@ SIG_DFL -- if the default action for the signal is in effect\n\
269269
None -- if an unknown handler is in effect\n\
270270
anything else -- the callable Python object used as a handler");
271271

272-
#ifdef HAVE_SIGPROCMASK /* we assume that having SIGPROCMASK is enough
273-
to guarantee full POSIX signal handling */
274-
/* returns 0 for success, <0 for failure (with exception set) */
275-
static int
276-
_signal_list_to_sigset(PyObject* seq, sigset_t* set, char* mesg)
277-
{
278-
int i, len, val;
279-
280-
seq = PySequence_Fast(seq, mesg);
281-
if (!seq)
282-
return -1;
283-
284-
len = PySequence_Fast_GET_SIZE(seq);
285-
286-
sigemptyset(set);
287-
288-
for (i = 0; i < len; i++) {
289-
val = PyInt_AsLong(PySequence_Fast_GET_ITEM(seq, i));
290-
if (val == -1 && PyErr_Occurred()) {
291-
Py_DECREF(seq);
292-
return -1;
293-
}
294-
if (sigaddset(set, val) < 0) {
295-
Py_DECREF(seq);
296-
PyErr_SetFromErrno(PyExc_ValueError);
297-
return -1;
298-
}
299-
}
300-
301-
Py_DECREF(seq);
302-
return 0;
303-
}
304-
305-
static PyObject*
306-
_signal_sigset_to_list(sigset_t* set)
307-
{
308-
PyObject* ret;
309-
PyObject* ob;
310-
int i;
311-
312-
ret = PyList_New(0);
313-
if (!ret)
314-
return NULL;
315-
316-
for (i = 1; i < NSIG; i++) {
317-
if (sigismember(set, i)) {
318-
ob = PyInt_FromLong(i);
319-
if (!ob) {
320-
Py_DECREF(ret);
321-
return NULL;
322-
}
323-
PyList_Append(ret, ob);
324-
Py_DECREF(ob);
325-
}
326-
}
327-
328-
return ret;
329-
}
330-
331-
static PyObject*
332-
signal_sigprocmask(PyObject* self, PyObject* args)
333-
{
334-
int how;
335-
sigset_t newset, oldset;
336-
PyObject* seq;
337-
338-
if (!PyArg_ParseTuple(args, "iO", &how, &seq))
339-
return NULL;
340-
341-
if (_signal_list_to_sigset(seq, &newset,
342-
"sigprocmask requires a sequence") < 0)
343-
return NULL;
344-
345-
if (sigprocmask(how, &newset, &oldset) < 0) {
346-
return PyErr_SetFromErrno(PyExc_ValueError);
347-
}
348-
349-
if (PyErr_CheckSignals())
350-
return NULL;
351-
352-
return _signal_sigset_to_list(&oldset);
353-
}
354-
355-
PyDoc_STRVAR(sigprocmask_doc,
356-
"sigprocmask(how, sigset) -> sigset\n\
357-
\n\
358-
Change the list of currently blocked signals. The parameter how should be\n\
359-
one of SIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK and sigset should be a\n\
360-
sequence of signal numbers. The behaviour of the call depends on the value\n\
361-
of how:\n\
362-
\n\
363-
SIG_BLOCK\n\
364-
The set of blocked signals is the union of the current set and the\n\
365-
sigset argument.\n\
366-
SIG_UNBLOCK\n\
367-
The signals in sigset are removed from the current set of blocked\n\
368-
signals. It is legal to attempt to unblock a signal which is not\n\
369-
blocked.\n\
370-
SIG_SETMASK\n\
371-
The set of blocked signals is set to the argument set.\n\
372-
\n\
373-
A list contating the numbers of the previously blocked signals is returned.");
374-
375-
static PyObject*
376-
signal_sigpending(PyObject* self)
377-
{
378-
sigset_t set;
379-
380-
if (sigpending(&set) < 0) {
381-
return PyErr_SetFromErrno(PyExc_ValueError);
382-
}
383-
384-
return _signal_sigset_to_list(&set);
385-
}
386-
387-
PyDoc_STRVAR(sigpending_doc,
388-
"sigpending() -> sigset\n\
389-
\n\
390-
Return the set of pending signals, i.e. a list containing the numbers of\n\
391-
those signals that have been raised while blocked.");
392-
393-
static PyObject*
394-
signal_sigsuspend(PyObject* self, PyObject* arg)
395-
{
396-
sigset_t set;
397-
398-
if (_signal_list_to_sigset(arg, &set,
399-
"sigsuspend requires a sequence") < 0)
400-
return NULL;
401-
402-
Py_BEGIN_ALLOW_THREADS
403-
sigsuspend(&set);
404-
Py_END_ALLOW_THREADS
405-
406-
if (PyErr_CheckSignals())
407-
return NULL;
408-
409-
Py_INCREF(Py_None);
410-
return Py_None;
411-
}
412-
413-
PyDoc_STRVAR(sigsuspend_doc,
414-
"sigsuspend(sigset) -> None\n\
415-
\n\
416-
Temporarily replace the signal mask with sigset (which should be a sequence\n\
417-
of signal numbers) and suspend the process until a signal is received.");
418-
#endif
419272

420273
/* List of functions defined in the module */
421274
static PyMethodDef signal_methods[] = {
@@ -430,14 +283,6 @@ static PyMethodDef signal_methods[] = {
430283
#endif
431284
{"default_int_handler", signal_default_int_handler,
432285
METH_VARARGS, default_int_handler_doc},
433-
#ifdef HAVE_SIGPROCMASK
434-
{"sigprocmask", (PyCFunction)signal_sigprocmask,
435-
METH_VARARGS, sigprocmask_doc},
436-
{"sigpending", (PyCFunction)signal_sigpending,
437-
METH_NOARGS, sigpending_doc},
438-
{"sigsuspend", (PyCFunction)signal_sigsuspend,
439-
METH_O, sigsuspend_doc},
440-
#endif
441286
{NULL, NULL} /* sentinel */
442287
};
443288

@@ -453,10 +298,6 @@ getsignal() -- get the signal action for a given signal\n\
453298
pause() -- wait until a signal arrives [Unix only]\n\
454299
default_int_handler() -- default SIGINT handler\n\
455300
\n\
456-
sigpending() |\n\
457-
sigprocmask() |-- posix signal mask handling [Unix only]\n\
458-
sigsuspend() |\n\
459-
\n\
460301
Constants:\n\
461302
\n\
462303
SIG_DFL -- used to refer to the system default handler\n\
@@ -705,18 +546,6 @@ initsignal(void)
705546
PyDict_SetItemString(d, "SIGINFO", x);
706547
Py_XDECREF(x);
707548
#endif
708-
#ifdef HAVE_SIGPROCMASK
709-
x = PyInt_FromLong(SIG_BLOCK);
710-
PyDict_SetItemString(d, "SIG_BLOCK", x);
711-
Py_XDECREF(x);
712-
x = PyInt_FromLong(SIG_UNBLOCK);
713-
PyDict_SetItemString(d, "SIG_UNBLOCK", x);
714-
Py_XDECREF(x);
715-
x = PyInt_FromLong(SIG_SETMASK);
716-
PyDict_SetItemString(d, "SIG_SETMASK", x);
717-
Py_XDECREF(x);
718-
#endif
719-
720549
if (!PyErr_Occurred())
721550
return;
722551

0 commit comments

Comments
 (0)