Skip to content

@minrk /slow_server.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
"""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()
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
Something went wrong with that request. Please try again.