[Zope-Checkins] CVS: Zope/lib/python/Signals - SignalHandler.py:1.2
Guido van Rossum
guido@python.org
Mon, 11 Nov 2002 11:10:09 -0500
Update of /cvs-repository/Zope/lib/python/Signals
In directory cvs.zope.org:/tmp/cvs-serv18077
Modified Files:
SignalHandler.py
Log Message:
Don't be dependent on zdaemon.Daemon just to get the signal name.
=== Zope/lib/python/Signals/SignalHandler.py 1.1 => 1.2 ===
--- Zope/lib/python/Signals/SignalHandler.py:1.1 Sat Nov 9 13:30:54 2002
+++ Zope/lib/python/Signals/SignalHandler.py Mon Nov 11 11:10:09 2002
@@ -15,7 +15,6 @@
__version__='$Revision$'[11:-2]
-import Daemon
import sys, os
import signal, zLOG
@@ -36,7 +35,7 @@
if items is None:
items = self.registry[signum] = []
signal.signal(signum, self.signalHandler)
- signame = Daemon.get_signal_name(signum)
+ signame = get_signal_name(signum)
zLOG.LOG('Z2', zLOG.BLATHER, "Installed sighandler for %s" % (
signame
))
@@ -49,7 +48,7 @@
def signalHandler(self, signum, frame):
"""Meta signal handler that dispatches to registered handlers."""
- signame = Daemon.get_signal_name(signum)
+ signame = get_signal_name(signum)
zLOG.LOG('Z2', zLOG.INFO , "Caught signal %s" % signame)
for handler in self.registry.get(signum, []):
@@ -63,6 +62,25 @@
zLOG.LOG('Z2', zLOG.WARNING,
'A handler for %s failed!' % signame,
error=sys.exc_info())
+
+_signals = None
+
+def get_signal_name(n):
+ """Return the symbolic name for signal n.
+
+ Returns 'unknown' if there is no SIG name bound to n in the signal
+ module.
+ """
+ global _signals
+ if _signals is None:
+ _signals = {}
+ for k, v in signal.__dict__.items():
+ startswith = getattr(k, 'startswith', None)
+ if startswith is None:
+ continue
+ if startswith('SIG') and not startswith('SIG_'):
+ _signals[v] = k
+ return _signals.get(n, 'unknown')
# The SignalHandler is actually a singleton.
SignalHandler = SignalHandler()