标签:content ... gif asa pypi facebook ict 基类 att
from bottle import run
 
if __name__ == ‘__main__‘:
    def application(environ, start_response):
        start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)])
        return [‘<h1>Hello world!</h1>‘]
 
    run(host=‘localhost‘, port=8080, app=application)
from bottle import run
import gevent.monkey
gevent.monkey.patch_all()
 
if __name__ == ‘__main__‘:
    def application(environ, start_response):
        start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)])
        return [‘<h1>Hello world!</h1>‘]
 
    run(host=‘localhost‘, port=8080, app=application, server = ‘gevent‘)
通过server关键字指定web服务器为‘gevent’,输出的第一行变成了:

    def __call__(self, environ, start_response):
      """ Each instance of :class:‘Bottle‘ is a WSGI application. """
       return self.wsgi(environ, start_response)        
    def wsgi(self, environ, start_response):
        """ The bottle WSGI-interface. """
        try:
            out = self._cast(self._handle(environ))
            # rfc2616 section 4.3
            if response._status_code in (100, 101, 204, 304)            or environ[‘REQUEST_METHOD‘] == ‘HEAD‘:
                if hasattr(out, ‘close‘): out.close()
                out = []
            start_response(response._status_line, response.headerlist)
            return out
_handle:处理请求,最终调用到application ,简化后的代码如下:
1 def _handle(self, environ): 2 self.trigger_hook(‘before_request‘) 3 route, args = self.router.match(environ) 4 out = route.call(**args) 5 self.trigger_hook(‘after_request‘) 6 return out
A Router is an ordered collection of route->target pairs. It is used to efficiently match WSGI requests against a number of routes and return the first target that satisfies the request.
| Name | Homepage | Description | 
|---|---|---|
| cgi | Run as CGI script | |
| flup | flup | Run as FastCGI process | 
| gae | gae | Helper for Google App Engine deployments | 
| wsgiref | wsgiref | Single-threaded default server | 
| cherrypy | cherrypy | Multi-threaded and very stable | 
| paste | paste | Multi-threaded, stable, tried and tested | 
| rocket | rocket | Multi-threaded | 
| waitress | waitress | Multi-threaded, poweres Pyramid | 
| gunicorn | gunicorn | Pre-forked, partly written in C | 
| eventlet | eventlet | Asynchronous framework with WSGI support. | 
| gevent | gevent | Asynchronous (greenlets) | 
| diesel | diesel | Asynchronous (greenlets) | 
| fapws3 | fapws3 | Asynchronous (network side only), written in C | 
| tornado | tornado | Asynchronous, powers some parts of Facebook | 
| twisted | twisted | Asynchronous, well tested but... twisted | 
| meinheld | meinheld | Asynchronous, partly written in C | 
| bjoern | bjoern | Asynchronous, very fast and written in C | 
| auto | Automatically selects an available server adapter | 
标签:content ... gif asa pypi facebook ict 基类 att
原文地址:http://www.cnblogs.com/yezuhui/p/6855814.html