# -*- coding: utf-8 -*-
import os
import sys
import tornado.ioloop
import tornado.web
import tornado.wsgi
import tornado.httpserver
from django.core.handlers.wsgi import WSGIHandler # 设置 Django 设置模块,sets the default settings module to use
_HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.append(_HERE)
os.environ['DJANGO_SETTINGS_MODULE'] = "settings" def main(port):
# 利用 tornado 的http server处理消息请求
wsgi_app = tornado.wsgi.WSGIContainer(WSGIHandler())

# Application 处理请求消息
tornado_app = tornado.web.Application(
# FallbackHandler: A RequestHandler that wraps another HTTP server callback.
# http://www.tornadoweb.org/en/stable/web.html#tornado.web.FallbackHandler
[('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
]) # HTTPServer is a very basic connection handler. It parses the request headers and body
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(port)
tornado.ioloop.IOLoop.instance().start() if __name__ == '__main__':
try:
import setproctitle
setproctitle.setproctitle('www:' + sys.argv[1])
except ImportError:
pass
main(int(sys.argv[1]))

基本思想:利用 tornado 的 http server,处理消息请求。

官方文档有介绍:

  • WSGIContainer lets you run other WSGI applications and frameworks on the Tornado HTTP server. For example, with this class you can mix Django and Tornado handlers in a single server.

详细内容,见代码注释。

最新文章

  1. .NET平台开源项目速览(1)SharpConfig配置文件读写组件
  2. 关于模拟http请求 cookie的赋值
  3. POI2005Bank notes银行货币
  4. android自动获取短信验证码
  5. memcached for windows 修改端口和最大内存,以及常用命令
  6. 为python-sproto添加map支持
  7. Oracle计算时间差函数
  8. Phython 学习笔记之——类的初步认识
  9. java 开发环境
  10. XRDP与VNC的关系
  11. lintcode 1: Data Stream Median
  12. jq的合成事件
  13. Ubuntu16.04 安装Tensorflow1.7过程记录二:安装CUDA及Tensorflow
  14. jsp中${pageContext.request.contextPath}的意思
  15. “教你如何玩转Web响应式布局” 的更多相关文章
  16. 剑指offer-矩阵覆盖
  17. c#语言集合分析
  18. 【Vue学习笔记1】全局配置 Vue.config
  19. memcache图形管理工具
  20. 形象易懂讲解算法I——小波变换

热门文章

  1. (转)CentOS5.5 下搭建 PHP 环境(最佳的LAMP环境)
  2. 为什么乱码:<meta http-equiv="content-type">前的非ANSI字符
  3. spring @resource @ Autowired
  4. linux服务器重启服务命令说明文档
  5. hdu 1180 诡异的楼梯(广搜,简单)
  6. 拼写sql语句随笔
  7. HDU 4143 A Simple Problem(枚举)
  8. hdu 1524 A Chess Game 博弈论
  9. java使用正则表达式——实例
  10. cojs 香蕉 解题报告