Instantly share code, notes, and snippets.

Embed
What would you like to do?
Twisted Benchmark Example
""" A Twisted benchmark example. See:
http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/comment-page-1/#comment-32785
"""
from twisted.web import server, resource
class MainHandler(resource.Resource):
isLeaf = True
def render_GET(self, request):
value = request.args.get('value', [''])[0]
request.setHeader('Content-Type', 'text/xml')
if not value:
return '<http_test><error>no value specified</error></http_test>'
else:
return '<http_test><value>%s</value></http_test>' % value
if __name__ == '__main__':
from twisted.internet import epollreactor
epollreactor.install()
from twisted.internet import reactor
root = MainHandler()
factory = server.Site(root)
reactor.listenTCP(8080, factory)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment