With aiohttp server, it is possible to await
the request body asynchronously, that way it gives the hand back to the event loop:
async def post_handler(request):
data = await request.json()
return aiohttp.web.Response(status = 201, body = data, content_type='application/json')
However using Tornado I can't find a way to make it asynchronously. The only way to retrieve the body is this:
async def post(self):
data = self.request.body
self.write(data)
Therefore, if the client sends a big file, the tornado event loop will block until the whole body is retrieve, am I right ?
No, the event loop is not blocked. post()
is not run until the body is already fully loaded. To process the body incrementally, see the @stream_request_body
decorator.