我实际上发现Tornado(http://www.tornadoweb.cn/)作为一种服务我的Django应用程序的方式,但是我希望能够将它作为后台进程运行。到目前为止,我一直在关注来自上述存储库的https://github.com/bdarnell/django-tornado-demo/blob/master/testsite/tornado_main.py代码可执行文件。
#!/usr/bin/env python
# Run this with
# PYTHONPATH=. DJANGO_SETTINGS_MODULE=testsite.settings testsite/tornado_main.py
# Serves by default at
# http://localhost:8080/hello-tornado and
# http://localhost:8080/hello-django
from tornado.options import options, define, parse_command_line
import django.core.handlers.wsgi
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.wsgi
define('port', type=int, default=8080)
class HelloHandler(tornado.web.RequestHandler):
def get(self):
self.write('Hello from tornado')
def main():
parse_command_line()
wsgi_app = tornado.wsgi.WSGIContainer(
django.core.handlers.wsgi.WSGIHandler())
tornado_app = tornado.web.Application(
[
('/hello-tornado', HelloHandler),
('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
])
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
main()
截至目前,我一直在使用 PYTHONPATH =运行Tornado。在命令行中DJANGO_SETTINGS_MODULE = testsite.settings testsite / tornado_main.py 。我如何能够将其作为一个过程运行?感谢。