from twisted.internet import reactor from twisted.internet.task import deferLater from twisted.web.resource import Resource from twisted.web.server import Site, NOT_DONE_YET import time class BusyPage(Resource): isLeaf = True def _delayedRender(self, request): request.write("Finally done, at %s" % (time.ctime(),)) request.finish() def render_GET(self, request): d = deferLater(reactor, 5, lambda : request) d.addCallback(self._delayedRender) return NOT_DONE_YET factory = Site(BusyPage()) reactor.listenTCP(8000, factory) reactor.run()
时间: 2024-12-10 06:00:56