Last active
September 23, 2018 15:22
-
-
Save cgarciae/60343fae7988bd395eaf3bc38d3081f4 to your computer and use it in GitHub Desktop.
server.py
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
# server.py | |
from aiohttp import web | |
import asyncio | |
import random | |
async def handle(request): | |
await asyncio.sleep(random.randint(0, 3)) | |
return web.Response(text="Hello, World!") | |
async def init(): | |
app = web.Application() | |
app.router.add_route('GET', '/{name}', handle) | |
return await loop.create_server( | |
app.make_handler(), '127.0.0.1', 8080) | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(init()) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment