twisted 4 non block web server
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()
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。