sanic/examples/request_timeout.py

22 lines
474 B
Python
Raw Permalink Normal View History

import asyncio
2017-04-11 21:34:55 +01:00
from sanic import Sanic
from sanic import response
from sanic.config import Config
from sanic.exceptions import RequestTimeout
Config.REQUEST_TIMEOUT = 1
app = Sanic(__name__)
2016-11-26 05:47:42 +00:00
@app.route('/')
async def test(request):
await asyncio.sleep(3)
2017-04-11 21:34:55 +01:00
return response.text('Hello, world!')
@app.exception(RequestTimeout)
def timeout(request, exception):
2017-04-11 21:34:55 +01:00
return response.text('RequestTimeout from error_handler.', 408)
app.run(host='0.0.0.0', port=8000)