Created
June 10, 2012 06:38
-
-
Save jeethu/2904203 to your computer and use it in GitHub Desktop.
Test RequestHandler.prepare() and RequestHandler.on_finish() returning deferreds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cyclone.web | |
from twisted.internet import reactor | |
from twisted.internet.task import deferLater | |
class TestHandler(cyclone.web.RequestHandler): | |
def _prepare(self): | |
print "Prepared!" | |
def prepare(self): | |
print "Preparing" | |
return deferLater(reactor, 2, self._prepare) | |
def get(self): | |
self.write("Hello, world") | |
def _on_finish(self): | |
print "Finished!" | |
def on_finish(self): | |
print "On finish" | |
return deferLater(reactor, 2, self._on_finish) | |
def main(): | |
application = cyclone.web.Application([ | |
(r"/", TestHandler) | |
], debug=True) | |
reactor.listenTCP(8888, application, interface="127.0.0.1") | |
reactor.run() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment