欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python:tornado+wsgi异步处理请求

程序员文章站 2022-06-14 17:32:22
...

tornado版本:
python:tornado+wsgi异步处理请求
            
    
    博客分类: tornado 异步处理请求 tornadowsgipython异步处理 
 start_app.py

# coding:gbk

import tornado.web
import tornado.wsgi
import wsgiref.simple_server

import sys
import for_rmzx

reload(sys)
sys.setdefaultencoding('gbk')

class MainHandler_gjj(tornado.web.RequestHandler):

    def initialize(self,param):
        self.param = param

    def get(self):
        # name = self.get_argument("name")
        self.write("Hello, gjj:" + self.param)

class MainHandler_sb(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, sb")

class StoryHandler(tornado.web.RequestHandler):
    def get(self, param1,param2,parma3):
        self.write("for test ref params " + param1 + "----------" + param2 + "----------" + parma3)

if __name__ == "__main__":
    application_bjgjj = tornado.web.Application([
        (r"/gjj", MainHandler_gjj, dict(param="andy")),
        (r"/sb", MainHandler_sb),
        (r"/rmzx", for_rmzx.MainHandler_rmzx),
        (r"/api/param/([a-z]+)/([0-9]+)/([a-zA-Z0-9\u4e00-\u9fa5]+)", StoryHandler),
    ])
    wsgi_app = tornado.wsgi.WSGIAdapter(application_bjgjj)
    server = wsgiref.simple_server.make_server('', 5555, wsgi_app)
    server.serve_forever()

 for_rmzx.py

__author__ = 'sks'

import tornado.web
import tornado.wsgi
import wsgiref.simple_server

class MainHandler_rmzx(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, rmzx")

 在 start_app.py 启动即可,访问localhost:5555/gjj即可返回相应数据薪资

  • python:tornado+wsgi异步处理请求
            
    
    博客分类: tornado 异步处理请求 tornadowsgipython异步处理 
  • 大小: 27.2 KB