Added support for Tornado.

Took less than a beer.
This commit is contained in:
Paul J. Davis 2010-04-15 21:20:52 -04:00
parent 0c935d06c7
commit d14389cb68
3 changed files with 41 additions and 0 deletions

11
examples/tornado/basic.py Normal file
View File

@ -0,0 +1,11 @@
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
app = tornado.web.Application([
(r"/", MainHandler)
])

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop, PeriodicCallback
from gunicorn.workers.base import Worker
class TornadoWorker(Worker):
def watchdog(self):
self.notify()
if self.ppid != os.getppid():
self.log.info("Parent changed, shutting down: %s" % self)
self.ioloop.stop()
def run(self):
self.socket.setblocking(0)
self.ioloop = IOLoop.instance()
PeriodicCallback(self.watchdog, 1000, io_loop=self.ioloop).start()
server = HTTPServer(self.app, io_loop=self.ioloop)
server._socket = self.socket
server.start(num_processes=1)
self.ioloop.start()

View File

@ -52,6 +52,7 @@ setup(
sync=gunicorn.workers.sync:SyncWorker
eventlet=gunicorn.workers.geventlet:EventletWorker
gevent=gunicorn.workers.ggevent:GEventWorker
tornado=gunicorn.workers.gtornado:TornadoWorker
[paste.server_runner]
main=gunicorn.main:paste_server