sanic/examples/request_timeout.py
Adam Hopkins 8c07e388cd
LTS v21.12 Deprecations (#2306)
Co-authored-by: Néstor Pérez <25409753+prryplatypus@users.noreply.github.com>
2021-12-24 00:30:27 +02:00

24 lines
461 B
Python

import asyncio
from sanic import Sanic, response
from sanic.config import Config
from sanic.exceptions import RequestTimeout
Config.REQUEST_TIMEOUT = 1
app = Sanic("Example")
@app.route("/")
async def test(request):
await asyncio.sleep(3)
return response.text("Hello, world!")
@app.exception(RequestTimeout)
def timeout(request, exception):
return response.text("RequestTimeout from error_handler.", 408)
app.run(host="0.0.0.0", port=8000)