Commit f6ae33b4 authored by Lennart Regebro's avatar Lennart Regebro

Neater shutdown with twisted.

parent 286a3dae
......@@ -31,6 +31,11 @@ def shutdown(exit_code,fast = 0):
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
......
......@@ -313,6 +313,7 @@ class ChannelPipe:
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])
......
......@@ -33,5 +33,6 @@ class ZServerPublisher:
for r in res:
a['wsgi.output'].write(r)
finally:
# TODO: Support keeping connections open.
a['wsgi.output']._close = 1
a['wsgi.output'].close()
......@@ -115,12 +115,15 @@ class ZopeStarter:
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment