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): ...@@ -31,6 +31,11 @@ def shutdown(exit_code,fast = 0):
import ZServer import ZServer
ZServer.exit_code = exit_code ZServer.exit_code = exit_code
_shutdown_phase = 1 _shutdown_phase = 1
try:
from twisted.internet import reactor
reactor.callLater(0.1, reactor.stop)
except ImportError:
pass
if fast: if fast:
# Someone wants us to shutdown fast. This is hooked into SIGTERM - so # 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 # possibly the system is going down and we can expect a SIGKILL within
......
...@@ -313,6 +313,7 @@ class ChannelPipe: ...@@ -313,6 +313,7 @@ class ChannelPipe:
def start_response(self, status, headers, exc_info=None): def start_response(self, status, headers, exc_info=None):
# Used for WSGI # Used for WSGI
self._request.reply_code = int(status.split(' ')[0])
status = 'HTTP/%s %s\r\n' % (self._request.version, status) status = 'HTTP/%s %s\r\n' % (self._request.version, status)
self.write(status) self.write(status)
headers = '\r\n'.join([': '.join(x) for x in headers]) headers = '\r\n'.join([': '.join(x) for x in headers])
......
...@@ -33,5 +33,6 @@ class ZServerPublisher: ...@@ -33,5 +33,6 @@ class ZServerPublisher:
for r in res: for r in res:
a['wsgi.output'].write(r) a['wsgi.output'].write(r)
finally: finally:
# TODO: Support keeping connections open.
a['wsgi.output']._close = 1 a['wsgi.output']._close = 1
a['wsgi.output'].close() a['wsgi.output'].close()
...@@ -115,12 +115,15 @@ class ZopeStarter: ...@@ -115,12 +115,15 @@ class ZopeStarter:
try: try:
from App.config import getConfiguration from App.config import getConfiguration
config = getConfiguration() config = getConfiguration()
import ZServer
if config.twisted_servers: if config.twisted_servers:
if not _use_twisted: if not _use_twisted:
raise ImportError("You do not have twisted installed.") raise ImportError("You do not have twisted installed.")
twisted.internet.reactor.run() twisted.internet.reactor.run()
# Storing the exit code in the ZServer even for twisted,
# but hey, it works...
sys.exit(ZServer.exit_code)
else: else:
import ZServer
import Lifetime import Lifetime
Lifetime.loop() Lifetime.loop()
sys.exit(ZServer.exit_code) 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