sanic/tests/performance/aiohttp/simple_server.py

25 lines
476 B
Python
Raw Permalink Normal View History

2016-10-15 04:06:29 +01:00
# Run with python3 simple_server.py PORT
import asyncio
import sys
import ujson as json
import uvloop
from aiohttp import web
2016-10-15 04:06:29 +01:00
loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)
2018-12-30 11:18:06 +00:00
2016-10-15 04:06:29 +01:00
async def handle(request):
2018-12-30 11:18:06 +00:00
return web.Response(
body=json.dumps({"test": True}).encode("utf-8"),
content_type="application/json",
)
2016-10-15 04:06:29 +01:00
app = web.Application(loop=loop)
2018-12-30 11:18:06 +00:00
app.router.add_route("GET", "/", handle)
2016-10-15 04:06:29 +01:00
web.run_app(app, port=sys.argv[1], access_log=None)