Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
"""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):
def get(self, page):
loop = ioloop.IOLoop.instance()
loop.add_timeout(loop.time() + self.settings['delay'],
lambda : self.finish(page),
if __name__ == '__main__':
app = web.Application([
(r'/(\d+)', SlowHandler)
], delay=options.options.delay,
http_server = httpserver.HTTPServer(app)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment