[Zope-Checkins] SVN: Zope/branches/regebro-wsgi_support2/lib/python/ Neater shutdown with twisted.

Lennart Regebro regebro at gmail.com
Mon May 1 06:12:03 EDT 2006


Log message for revision 67785:
  Neater shutdown with twisted.
  

Changed:
  U   Zope/branches/regebro-wsgi_support2/lib/python/Lifetime/__init__.py
  U   Zope/branches/regebro-wsgi_support2/lib/python/ZServer/HTTPResponse.py
  U   Zope/branches/regebro-wsgi_support2/lib/python/ZServer/PubCore/ZServerPublisher.py
  U   Zope/branches/regebro-wsgi_support2/lib/python/Zope2/Startup/__init__.py

-=-
Modified: Zope/branches/regebro-wsgi_support2/lib/python/Lifetime/__init__.py
===================================================================
--- Zope/branches/regebro-wsgi_support2/lib/python/Lifetime/__init__.py	2006-05-01 10:11:02 UTC (rev 67784)
+++ Zope/branches/regebro-wsgi_support2/lib/python/Lifetime/__init__.py	2006-05-01 10:12:03 UTC (rev 67785)
@@ -31,6 +31,11 @@
         import ZServer
         ZServer.exit_code = exit_code
         _shutdown_phase = 1
+        try:
+            from twisted.internet import reactor
+            reactor.callLater(0.1, reactor.stop)
+        except ImportError:
+            pass
     if fast:
         # Someone wants us to shutdown fast. This is hooked into SIGTERM - so
         # possibly the system is going down and we can expect a SIGKILL within

Modified: Zope/branches/regebro-wsgi_support2/lib/python/ZServer/HTTPResponse.py
===================================================================
--- Zope/branches/regebro-wsgi_support2/lib/python/ZServer/HTTPResponse.py	2006-05-01 10:11:02 UTC (rev 67784)
+++ Zope/branches/regebro-wsgi_support2/lib/python/ZServer/HTTPResponse.py	2006-05-01 10:12:03 UTC (rev 67785)
@@ -313,6 +313,7 @@
 
     def start_response(self, status, headers, exc_info=None):
         # Used for WSGI
+        self._request.reply_code = int(status.split(' ')[0])
         status = 'HTTP/%s %s\r\n' % (self._request.version, status)
         self.write(status)
         headers = '\r\n'.join([': '.join(x) for x in headers])

Modified: Zope/branches/regebro-wsgi_support2/lib/python/ZServer/PubCore/ZServerPublisher.py
===================================================================
--- Zope/branches/regebro-wsgi_support2/lib/python/ZServer/PubCore/ZServerPublisher.py	2006-05-01 10:11:02 UTC (rev 67784)
+++ Zope/branches/regebro-wsgi_support2/lib/python/ZServer/PubCore/ZServerPublisher.py	2006-05-01 10:12:03 UTC (rev 67785)
@@ -33,5 +33,6 @@
                     for r in res:
                         a['wsgi.output'].write(r)
                 finally:
+                    # TODO: Support keeping connections open.
                     a['wsgi.output']._close = 1
                     a['wsgi.output'].close()

Modified: Zope/branches/regebro-wsgi_support2/lib/python/Zope2/Startup/__init__.py
===================================================================
--- Zope/branches/regebro-wsgi_support2/lib/python/Zope2/Startup/__init__.py	2006-05-01 10:11:02 UTC (rev 67784)
+++ Zope/branches/regebro-wsgi_support2/lib/python/Zope2/Startup/__init__.py	2006-05-01 10:12:03 UTC (rev 67785)
@@ -115,12 +115,15 @@
         try:
             from App.config import getConfiguration
             config = getConfiguration()
+            import ZServer
             if config.twisted_servers:
                 if not _use_twisted:
                     raise ImportError("You do not have twisted installed.")
                 twisted.internet.reactor.run()
+                # Storing the exit code in the ZServer even for twisted, 
+                # but hey, it works...
+                sys.exit(ZServer.exit_code)
             else:
-                import ZServer
                 import Lifetime
                 Lifetime.loop()
                 sys.exit(ZServer.exit_code)



More information about the Zope-Checkins mailing list