Could you please help me to understand how Sanic configuration will work when we have blocking code as part of some methods.
For Instance in below example I have set response timeout as 1 sec in configuration but , it looks like it is not considering configuration response time value and code is waiting for whole 2 sec time.sleep(2) and returning the response. As per my understanding here I would except sanic return 503 response timeout in 1 sec ? please correct me if I am missing something here.
Same code is working as excepted, if I use asycio.sleep instead of sleep
from time import sleep
from sanic import Sanic
from sanic.log import logger
from sanic.response import text
Sanic_CONFIG = {
“REQUEST_MAX_SIZE”: 10000,
“REQUEST_BUFFER_QUEUE_SIZE”: 2000,
“REQUEST_TIMEOUT”: 1,
“RESPONSE_TIMEOUT”: 1,
“KEEP_ALIVE”: True,
“KEEP_ALIVE_TIMEOUT”: 15,
“ACCESS_LOG”: False
}
app = Sanic(‘Config Example’)
app.config.update(Sanic_CONFIG)
@app.route(’/’)
async def test(request):
sleep(2)
logger.info(‘Here is your log’)
return text(‘Hello World!’)
if name == “main”:
app.run(debug=True, access_log=True)