class Simple(resource.Resource):
    isLeaf = True

def render_GET(self, request):
    return '<html>%s Iterations!</html>' % n

def main():
    global n
site = server.Site(Simple())
reactor.listenTCP(8080, site)
reactor.startRunning(False)
n = 0
while True:
    n += 1
if n % 1000 == 0:
    print(n)
time.sleep(0.001)
reactor.iterate()
if __name__ == '__main__':
    main()
Integrating a simple web server into a custom main loop in python?