Update run_async demo

This commit is contained in:
Shawn Niederriter 2017-04-06 14:39:54 -04:00 committed by GitHub
parent 833b14e353
commit 46ac79f4dc

View File

@ -1,5 +1,5 @@
from sanic import Sanic from sanic import Sanic
from sanic.response import json from sanic import response
from multiprocessing import Event from multiprocessing import Event
from signal import signal, SIGINT from signal import signal, SIGINT
import asyncio import asyncio
@ -9,10 +9,10 @@ app = Sanic(__name__)
@app.route("/") @app.route("/")
async def test(request): async def test(request):
return json({"answer": "42"}) return response.json({"answer": "42"})
asyncio.set_event_loop(uvloop.new_event_loop()) asyncio.set_event_loop(uvloop.new_event_loop())
server = app.create_server(host="0.0.0.0", port=8001) server = app.create_server(host="0.0.0.0", port=8080)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
task = asyncio.ensure_future(server) task = asyncio.ensure_future(server)
signal(SIGINT, lambda s, f: loop.stop()) signal(SIGINT, lambda s, f: loop.stop())