Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Twisted Benchmark Example
""" A Twisted benchmark example. See:
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>'
return '<http_test><value>%s</value></http_test>' % value
if __name__ == '__main__':
from twisted.internet import epollreactor
from twisted.internet import reactor
root = MainHandler()
factory = server.Site(root)
reactor.listenTCP(8080, factory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment