Change Request timeout process

This add a request timeout exception.
It cancels task, when request is timeout.
This commit is contained in:
38elements
2016-11-26 13:55:45 +09:00
parent fc19f2ea34
commit c01cbb3a8c
5 changed files with 88 additions and 6 deletions

View File

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