2016-11-26 04:55:45 +00:00
|
|
|
import asyncio
|
2017-04-11 21:34:55 +01:00
|
|
|
from sanic import Sanic
|
2017-05-13 15:01:35 +01:00
|
|
|
from sanic.response import text
|
2016-11-26 04:55:45 +00:00
|
|
|
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('/')
|
2016-11-26 04:55:45 +00:00
|
|
|
async def test(request):
|
|
|
|
await asyncio.sleep(3)
|
2017-05-13 15:01:35 +01:00
|
|
|
return text('Hello, world!')
|
2016-11-26 04:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.exception(RequestTimeout)
|
|
|
|
def timeout(request, exception):
|
2017-05-13 15:01:35 +01:00
|
|
|
return text('RequestTimeout from error_handler.', 408)
|
2016-11-26 04:55:45 +00:00
|
|
|
|
2017-05-13 15:01:35 +01:00
|
|
|
|
|
|
|
app.run(host='127.0.0.1', port=8000)
|