Skip to main content

tornado middleware

Project description

Middleware for tornado

[![Build Status](](

## Installation

pip install tmiddleware


git clone cd tmiddleware python install

## Requirements

  • python 2.6 or 2.7
  • tornado 2.4+

## Minimal Demo

### $ more examples/

import tornado import tornado.httpserver from tornado.options import define, options from tornado.web import RequestHandler

from tmiddleware.handler import TMiddlewareHandler

define(‘port’, 7777) MIDDLEWARES = [‘plugins.slow_request.SlowRequestMiddleware’, ‘plugins.profile.ProfileMiddleware’] define(“middlewares”, default=MIDDLEWARES, help=”middleware class list”)

class With(TMiddlewareHandler):
def get(self):
import time time.sleep(4) return self.finish(‘Hello World!’)
def run():
application = tornado.web.Application([(‘/’, With)]) http_server = tornado.httpserver.HTTPServer(application, xheaders=True) http_server.listen(options.port, ‘’) tornado.ioloop.IOLoop.instance().start()
if __name__ == ‘__main__’:

此处使用了自带的两个 middleware,一个用于查看请求的 profile 信息,一个用于在终端下记录超时的请求

### $ python

### $ chrome http://localhost:7777/?__profile__=true







  1. profile: 查看请求的内部函数耗时信息
  2. slow_request: 记录超时请求


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for TMiddleware, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size TMiddleware-0.0.1.tar.gz (117.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page