Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Twisted - Python Multi Threaded Web Server
from twisted.web import server, resource
from twisted.internet import reactor, endpoints
class Counter(resource.Resource):
isLeaf = True
numberRequests = 0
def render_GET(self, request):
self.numberRequests += 1
request.setHeader("content-type", "text/plain")
return "I am request #" + str(self.numberRequests) + "\n"
def render_POST(self, request):
print "I got POST!"
return "Good Work"
endpoints.serverFromString(reactor, "tcp:80").listen(server.Site(Counter()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment