Created
September 1, 2013 21:20
-
-
Save minrk/6407393 to your computer and use it in GitHub Desktop.
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
"""Simple server for testing code against a slow-responding server. | |
requests to '/INTEGER' are replied to with 'INTEGER', | |
after an artificial delay. | |
""" | |
import time | |
from tornado import web, ioloop, options, httpserver | |
options.define("port", default=8888, help="run on the given port", type=int) | |
options.define("delay", default=0.2, help="delay builtin to each request", type=float) | |
class SlowHandler(web.RequestHandler): | |
@web.asynchronous | |
def get(self, page): | |
loop = ioloop.IOLoop.instance() | |
loop.add_timeout(loop.time() + self.settings['delay'], | |
lambda : self.finish(page), | |
) | |
if __name__ == '__main__': | |
options.parse_command_line() | |
app = web.Application([ | |
(r'/(\d+)', SlowHandler) | |
], delay=options.options.delay, | |
) | |
http_server = httpserver.HTTPServer(app) | |
http_server.listen(options.options.port) | |
ioloop.IOLoop.instance().start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment