首頁  >  文章  >  後端開發  >  python:tornado+wsgi非同步處理請求

python:tornado+wsgi非同步處理請求

巴扎黑
巴扎黑原創
2016-11-07 11:26:152037瀏覽

tornado版本:
python:tornado+wsgi非同步處理請求 start_app.py

Java程式碼  

<strong># coding:gbk  
  
import tornado.web  
import tornado.wsgi  
import wsgiref.simple_server  
  
import sys  
import for_rmzx  
  
reload(sys)  
sys.setdefaultencoding(&#39;gbk&#39;)  
  
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(&#39;&#39;, 5555, wsgi_app)  
    server.serve_forever()</strong>

 for_rmzx.py

Java

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn