diff --git a/Include/pyerrors.h b/Include/pyerrors.h
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -311,11 +311,11 @@
#endif
-/* In sigcheck.c or signalmodule.c */
+/* In sigcheck.c or _signalmodule.c */
PyAPI_FUNC(int) PyErr_CheckSignals(void);
PyAPI_FUNC(void) PyErr_SetInterrupt(void);
-/* In signalmodule.c */
+/* In _signalmodule.c */
#ifndef Py_LIMITED_API
int PySignal_SetWakeupFd(int fd);
#endif
diff --git a/Lib/signal.py b/Lib/signal.py
new file mode 100644
--- /dev/null
+++ b/Lib/signal.py
@@ -0,0 +1,12 @@
+from _signal import *
+from enum import IntEnum as _IntEnum
+
+Signals = _IntEnum(
+ 'Signals',
+ {name: value for name, value in globals().items()
+ if name.isupper()
+ and (name.startswith('SIG') and not name.startswith('SIG_'))
+ or name.startswith('CTRL_')})
+
+globals().update(Signals.__members__)
+del _IntEnum
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -1,6 +1,7 @@
import unittest
from test import support
from contextlib import closing
+import enum
import gc
import pickle
import select
@@ -39,6 +40,25 @@
return None
+class GenericTests(unittest.TestCase):
+
+ def test_enum_constants(self):
+ import _signal
+ sig = signal.SIGTERM
+ int(sig)
+ self.assertEqual(str(sig), 'Signals.SIGTERM')
+ self.assertEqual(signal.SIGTERM, _signal.SIGTERM)
+ for name in dir(signal):
+ sig = getattr(signal, name)
+ if name.startswith('SIG_'):
+ self.assertIsInstance(sig, int)
+ elif name.startswith('SIG'):
+ self.assertIsInstance(sig, enum.IntEnum)
+ elif name.startswith("CTRL_"):
+ self.assertEqual(sys.platform, "win32")
+ self.assertIsInstance(sig, enum.IntEnum)
+
+
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
class InterProcessSignalTests(unittest.TestCase):
MAX_DURATION = 20 # Entire test should last at most 20 sec.
@@ -348,7 +368,7 @@
dt = after_time - mid_time
if dt >= TIMEOUT_HALF:
raise Exception("%s >= %s" % (dt, TIMEOUT_HALF))
- """, signal.SIGALRM)
+ """, int(signal.SIGALRM))
def test_wakeup_fd_during(self):
self.check_wakeup("""def test():
@@ -371,14 +391,14 @@
dt = after_time - before_time
if dt >= TIMEOUT_HALF:
raise Exception("%s >= %s" % (dt, TIMEOUT_HALF))
- """, signal.SIGALRM)
+ """, int(signal.SIGALRM))
def test_signum(self):
self.check_wakeup("""def test():
signal.signal(signal.SIGUSR1, handler)
os.kill(os.getpid(), signal.SIGUSR1)
os.kill(os.getpid(), signal.SIGALRM)
- """, signal.SIGUSR1, signal.SIGALRM)
+ """, int(signal.SIGUSR1), int(signal.SIGALRM))
@unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
'need signal.pthread_sigmask()')
@@ -395,7 +415,7 @@
os.kill(os.getpid(), signum2)
# Unblocking the 2 signals calls the C signal handler twice
signal.pthread_sigmask(signal.SIG_UNBLOCK, (signum1, signum2))
- """, signal.SIGUSR1, signal.SIGUSR2, ordered=False)
+ """, int(signal.SIGUSR1), int(signal.SIGUSR2), ordered=False)
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
@@ -660,6 +680,7 @@
code = '''if 1:
import signal
import sys
+ from signal import Signals
def handler(signum, frame):
1/0
@@ -928,7 +949,7 @@
def test_main():
try:
- support.run_unittest(PosixTests, InterProcessSignalTests,
+ support.run_unittest(GenericTests, PosixTests, InterProcessSignalTests,
WakeupFDTests, WakeupSignalTests,
SiginterruptTest, ItimerTest, WindowsSignalTests,
PendingSignalsTests)
diff --git a/Makefile.pre.in b/Makefile.pre.in
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -241,7 +241,7 @@
Modules/main.o \
Modules/gcmodule.o
-# Used of signalmodule.o is not available
+# Used of _signalmodule.o is not available
SIGNAL_OBJS= @SIGNAL_OBJS@
IO_H= Modules/_io/_iomodule.h
@@ -711,7 +711,7 @@
Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h
-Modules/signalmodule.o: $(srcdir)/Modules/signalmodule.c $(srcdir)/Modules/posixmodule.h
+Modules/_signalmodule.o: $(srcdir)/Modules/_signalmodule.c $(srcdir)/Modules/posixmodule.h
Python/dynload_shlib.o: $(srcdir)/Python/dynload_shlib.c Makefile
$(CC) -c $(PY_CORE_CFLAGS) \
diff --git a/Modules/Setup.config.in b/Modules/Setup.config.in
--- a/Modules/Setup.config.in
+++ b/Modules/Setup.config.in
@@ -7,7 +7,7 @@
@USE_THREAD_MODULE@_thread _threadmodule.c
# The signal module
-@USE_SIGNAL_MODULE@signal signalmodule.c
+@USE_SIGNAL_MODULE@signal _signalmodule.c
# The rest of the modules previously listed in this file are built
# by the setup.py script in Python 2.1 and later.
diff --git a/Modules/signalmodule.c b/Modules/_signalmodule.c
rename from Modules/signalmodule.c
rename to Modules/_signalmodule.c
--- a/Modules/signalmodule.c
+++ b/Modules/_signalmodule.c
@@ -956,7 +956,7 @@
static struct PyModuleDef signalmodule = {
PyModuleDef_HEAD_INIT,
- "signal",
+ "_signal",
module_doc,
-1,
signal_methods,
@@ -967,7 +967,7 @@
};
PyMODINIT_FUNC
-PyInit_signal(void)
+PyInit__signal(void)
{
PyObject *m, *d, *x;
int i;
@@ -1380,7 +1380,7 @@
void
PyOS_InitInterrupts(void)
{
- PyObject *m = PyImport_ImportModule("signal");
+ PyObject *m = PyImport_ImportModule("_signal");
if (m) {
Py_DECREF(m);
}
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -85,7 +85,7 @@
static user_signal_t *user_signals;
-/* the following macros come from Python: Modules/signalmodule.c */
+/* the following macros come from Python: Modules/_signalmodule.c */
#ifndef NSIG
# if defined(_NSIG)
# define NSIG _NSIG /* For BSD/SysV */
diff --git a/PC/VS9.0/pythoncore.vcproj b/PC/VS9.0/pythoncore.vcproj
--- a/PC/VS9.0/pythoncore.vcproj
+++ b/PC/VS9.0/pythoncore.vcproj
@@ -1151,7 +1151,7 @@
>
-
+
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -539,7 +539,7 @@
Modules
-
+
Modules
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -2861,7 +2861,7 @@
PyOS_setsig(int sig, PyOS_sighandler_t handler)
{
#ifdef HAVE_SIGACTION
- /* Some code in Modules/signalmodule.c depends on sigaction() being
+ /* Some code in Modules/_signalmodule.c depends on sigaction() being
* used here if HAVE_SIGACTION is defined. Fix that if this code
* changes to invalidate that assumption.
*/
diff --git a/Python/sigcheck.c b/Python/sigcheck.c
--- a/Python/sigcheck.c
+++ b/Python/sigcheck.c
@@ -4,7 +4,7 @@
file (and the whole directory it is in) doesn't know about objects
or exceptions. It can't be in errors.c because it can be
overridden (at link time) by a more powerful version implemented in
- signalmodule.c. */
+ _signalmodule.c. */
#include "Python.h"
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -9451,7 +9451,7 @@
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_dbmliborder" >&5
$as_echo "$with_dbmliborder" >&6; }
-# Determine if signalmodule should be used.
+# Determine if _signalmodule should be used.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-signal-module" >&5
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -2420,7 +2420,7 @@
fi])
AC_MSG_RESULT($with_dbmliborder)
-# Determine if signalmodule should be used.
+# Determine if _signalmodule should be used.
AC_SUBST(USE_SIGNAL_MODULE)
AC_SUBST(SIGNAL_OBJS)
AC_MSG_CHECKING(for --with-signal-module)