Cherrypy 是什么?美味的樱桃!

很早,很早的时候,就有了 Cherrypy。但是应用却并不广泛,无妨,许多人仍然会提起他的优异!web.py 就内置了 Cherrypy,还有 TG,还有 webfaction 的管理后台就是用 Cherrypy 做的。但是也因为他太基础,提供得太少,仅被其他框架作为基础 HTTP 服务来看待。

简单了解一下他的特色:

  • A fast, HTTP/1.1-compliant, WSGI thread-pooled webserver. Typically, CherryPy itself takes only 1-2ms per page!
  • Support for any other WSGI-enabled webserver or adapter, including Apache, IIS, lighttpd, mod_python, FastCGI, SCGI, and mod_wsgi
  • Easy to run multiple HTTP servers (e.g. on multiple ports) at once
  • A powerful configuration system for developers and deployers alike
  • A flexible plugin system
  • Built-in tools for caching, encoding, sessions, authorization, static content, and many more
  • A native mod_python adapter
  • A complete test suite
  • Swappable and customizable...everything.
  • Built-in profiling, coverage, and testing support.

直接看 Hello world 比较实在,对吧?

import cherrypy

class HelloWorld(object):
    def index(self):
        return "Hello World!"
    index.exposed = True

cherrypy.quickstart(HelloWorld())

其实,Cherrypy 的性能也十分不错,见这里:http://cherrypy.org/wiki/CherryPySpeed,自带的 server 能跑500+请求。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。