Skip to content

Instantly share code, notes, and snippets.

@iximiuz
Created March 25, 2016 11:41
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 iximiuz/04efacfa9dda3cec968d to your computer and use it in GitHub Desktop.
Save iximiuz/04efacfa9dda3cec968d to your computer and use it in GitHub Desktop.
Simple async HTTP server to emulate long request processing
import sys
from asyncio import coroutine, sleep
from aiohttp import web
@coroutine
def handle(request):
seconds = float(request.match_info.get('seconds', 1))
yield from sleep(seconds)
text = "You've been waiting for {} seconds".format(seconds)
return web.Response(body=text.encode('utf-8'))
app = web.Application()
app.router.add_route('GET', '/delay/{seconds}', handle)
web.run_app(app, port=int(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment