1

我一直在对 BaseHTTPServer 进行大量研究,发现它对于多个请求并不是那么好。我浏览了这篇文章 http://metachris.org/2011/01/scaling-python-servers-with-worker-processes-and-socket-duplication/#python

我想知道为多个请求构建 HTTP 服务器的最佳方法是什么->

我对 HTTP 服务器的要求很简单——支持多个请求(每个请求可能运行一个 LONG Python 脚本)

直到现在我有以下选项->-BaseHTTPServer(线程不好)-Mod_Python(Apache 集成)-CherryPy?- 任何其他?

4

3 回答 3

2

我对 CherryPy Web 服务器非常幸运,它是最古老、最可靠的纯 Python Web 服务器之一。只需将您的应用程序编写为可调用的 WSGI,它应该很容易在 CherryPy 的多线程服务器下运行。

http://www.cherrypy.org/

于 2011-10-02T23:55:02.447 回答
1

Indeed, the the HTTP servers provided with the standard python library are meant only for light duty use; For moderate scaling (100's of concurrent connections), mod_wsgi in apache is a great choice.

If your needs are greater than that(10,000's of concurrent connections), You'll want to look at an asynchronous framework, such as Twisted or Tornado. The general structure of an asynchronous application is quite different, so if you think you're likely to need to go down that route, you should definitely start your project in one of those frameworks from the start

于 2011-10-02T23:39:14.650 回答
1

Tornado是 FriendFeed/Facebook 开发的一个非常好的和易于使用的异步事件循环/网络服务器。我个人有过很好的经验。您可以使用下面示例中的 HTTP 类,或者仅使用 io-loop 来多路复用纯 TCP 连接。

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.current().start()
于 2015-10-16T14:28:14.763 回答