[Zope-Checkins] CVS: Zope/lib/python/Signals - Signals.py:1.3.2.1.2.1

Toby Dickenson tdickenson@geminidataloggers.com
Thu, 10 Oct 2002 13:27:55 -0400


Update of /cvs-repository/Zope/lib/python/Signals
In directory cvs.zope.org:/tmp/cvs-serv27621/lib/python/Signals

Modified Files:
      Tag: toby-clean-shutdown-branch
	Signals.py 
Log Message:
draft implementation of the clean shutdown proposal. ZMI and signal-based shutdown methods now set a global variable. This global variable causes the main medusa loop to return. We then gradually shut down sockets, in the right order. If any clients are slowly downloading a file then they can cause the shutdown to be delayed by up to 30 seconds, to allow them time to complete. This is true unless the shutdown was triggered by SIGTERM - we need to shutdown fast because the whole machine might be going down, and we can expect a SIGKILL within a few seconds.

=== Zope/lib/python/Signals/Signals.py 1.3.2.1 => 1.3.2.1.2.1 ===
--- Zope/lib/python/Signals/Signals.py:1.3.2.1	Tue Oct  8 19:00:17 2002
+++ Zope/lib/python/Signals/Signals.py	Thu Oct 10 13:27:54 2002
@@ -21,20 +21,28 @@
 import zLOG
 import sys
 import ZLogger
+import Lifetime
+
+def shutdownFastHandler():
+    """Shutdown cleanly on SIGTERM. This is registered first,
+       so it should be called after all other handlers."""
+    closeall()
+    zLOG.LOG('Z2', zLOG.INFO , "Shutting down fast")
+    Lifetime.shutdown(0,fast=1)
 
 def shutdownHandler():
-    """Shutdown cleanly on SIGTERM, SIGINT. This is registered first,
+    """Shutdown cleanly on SIGINT. This is registered first,
        so it should be called after all other handlers."""
     closeall()
     zLOG.LOG('Z2', zLOG.INFO , "Shutting down")
-    sys.exit(0)
+    Lifetime.shutdown(0)
 
 def restartHandler():
     """Restart cleanly on SIGHUP. This is registered first, so it
        should be called after all other SIGHUP handlers."""
     closeall()
     zLOG.LOG('Z2', zLOG.INFO , "Restarting")
-    sys.exit(1)
+    Lifetime.shutdown(1)
 
 def logfileReopenHandler():
     """Reopen log files on SIGUSR2. This is registered first, so it
@@ -81,7 +89,7 @@
 
 def registerZopeSignals():
     import signal
-    SignalHandler.registerHandler(signal.SIGTERM, shutdownHandler)
+    SignalHandler.registerHandler(signal.SIGTERM, shutdownFastHandler)
     SignalHandler.registerHandler(signal.SIGINT, shutdownHandler)
     SignalHandler.registerHandler(signal.SIGHUP, restartHandler)
     SignalHandler.registerHandler(signal.SIGUSR2, logfileReopenHandler)