Created
March 25, 2016 11:41
-
-
Save iximiuz/04efacfa9dda3cec968d to your computer and use it in GitHub Desktop.
Simple async HTTP server to emulate long request processing
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
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