2016-11-26 04:55:45 +00:00
|
|
|
import asyncio
|
2021-12-23 22:30:27 +00:00
|
|
|
|
|
|
|
from sanic import Sanic, response
|
2016-11-26 04:55:45 +00:00
|
|
|
from sanic.config import Config
|
|
|
|
from sanic.exceptions import RequestTimeout
|
|
|
|
|
|
|
|
Config.REQUEST_TIMEOUT = 1
|
2021-12-23 22:30:27 +00:00
|
|
|
app = Sanic("Example")
|
2016-11-26 04:55:45 +00:00
|
|
|
|
|
|
|
|
2021-12-23 22:30:27 +00:00
|
|
|
@app.route("/")
|
2016-11-26 04:55:45 +00:00
|
|
|
async def test(request):
|
|
|
|
await asyncio.sleep(3)
|
2021-12-23 22:30:27 +00:00
|
|
|
return response.text("Hello, world!")
|
2016-11-26 04:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.exception(RequestTimeout)
|
|
|
|
def timeout(request, exception):
|
2021-12-23 22:30:27 +00:00
|
|
|
return response.text("RequestTimeout from error_handler.", 408)
|
|
|
|
|
2016-11-26 04:55:45 +00:00
|
|
|
|
2023-07-05 11:45:08 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run(host="0.0.0.0", port=8000)
|