2016-11-26 13:55:45 +09:00
|
|
|
import asyncio
|
2021-12-24 00:30:27 +02:00
|
|
|
|
|
|
|
from sanic import Sanic, response
|
2016-11-26 13:55:45 +09:00
|
|
|
from sanic.config import Config
|
|
|
|
from sanic.exceptions import RequestTimeout
|
|
|
|
|
2021-12-24 00:30:27 +02:00
|
|
|
|
2016-11-26 13:55:45 +09:00
|
|
|
Config.REQUEST_TIMEOUT = 1
|
2021-12-24 00:30:27 +02:00
|
|
|
app = Sanic("Example")
|
2016-11-26 13:55:45 +09:00
|
|
|
|
|
|
|
|
2021-12-24 00:30:27 +02:00
|
|
|
@app.route("/")
|
2016-11-26 13:55:45 +09:00
|
|
|
async def test(request):
|
|
|
|
await asyncio.sleep(3)
|
2021-12-24 00:30:27 +02:00
|
|
|
return response.text("Hello, world!")
|
2016-11-26 13:55:45 +09:00
|
|
|
|
|
|
|
|
|
|
|
@app.exception(RequestTimeout)
|
|
|
|
def timeout(request, exception):
|
2021-12-24 00:30:27 +02:00
|
|
|
return response.text("RequestTimeout from error_handler.", 408)
|
|
|
|
|
2016-11-26 13:55:45 +09:00
|
|
|
|
2021-12-24 00:30:27 +02:00
|
|
|
app.run(host="0.0.0.0", port=8000)
|