wsgi中间件,用于在web页面中嵌入丰富的探查器。
WSGIProfile的Python项目详细描述
首先安装wsgiprofile。您可能还需要安装python分析器 如果你在ubuntu上的话。
easy_install WSGIProfile sudo apt-get install python-profiler
接下来让我们创建一个非常简单的wsgi应用程序,它有一个很慢的功能:
import time def app(environ, start_response): time.sleep(2) start_response('200 OK', [('Content-Type', 'text/html')]) return ['Hello World!'] if __name__ == '__main__': from wsgiref.simple_server import make_server server = make_server('127.0.0.1', 8080, app) server.serve_forever()
把你的浏览器指向http://localhost:8080你就会看到“你好,世界!“。
向该应用程序添加分析信息就像包装 某些分析中间件中的应用程序功能:
app = ProfileMiddleware(app)
我们的示例如下:
import time def app(environ, start_response): time.sleep(2) start_response('200 OK', [('Content-Type', 'text/html')]) return ['Hello World!'] if __name__ == '__main__': from wsgiref.simple_server import make_server from wsgiprofile import ProfileMiddleware app = ProfileMiddleware(app) server = make_server('127.0.0.1', 8080, app) server.serve_forever()