Skip to content

Instantly share code, notes, and snippets.

@minrk
Created September 1, 2013 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minrk/6407393 to your computer and use it in GitHub Desktop.
Save minrk/6407393 to your computer and use it in GitHub Desktop.
"""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()
Display the source blob
Display the rendered blob
Raw
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