amulllb
amulllb

Reputation: 3166

Python HTTP Server available for Multiple Requests

I have been doing a lot of studying of the BaseHTTPServer and found that its not that good for multiple requests. I went through this article http://metachris.org/2011/01/scaling-python-servers-with-worker-processes-and-socket-duplication/#python

and I wanted to know what is the best way for building a HTTP Server for multiple requests ->

My requirements for the HTTP Server are simple - - support multiple requests (where each request may run a LONG Python Script)

Till now I have following options -> - BaseHTTPServer (with thread is not good) - Mod_Python (Apache intergration) - CherryPy? - Any other?

Upvotes: 2

Views: 5159

Answers (3)

Chris Hager
Chris Hager

Reputation: 459

Tornado is a really good and easy-to-use asynchronous event-loop / webserver developed by FriendFeed/Facebook. I've personally had very good experiences with it. You can use the HTTP classes as in the example below, or only the io-loop to multiplex plain TCP connections.

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()

Upvotes: 1

Brandon Rhodes
Brandon Rhodes

Reputation: 89405

I have had very good luck with the CherryPy web server, one of the oldest and most solid of the pure-Python web servers. Just write your application as a WSGI callable and it should be easy to run under CherryPy's multi-threaded server.

http://www.cherrypy.org/

Upvotes: 2

SingleNegationElimination
SingleNegationElimination

Reputation: 156158

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

Upvotes: 1

Related Questions