有没有办法从 POST/PUT 中使用 Tornado 服务器异步检索正文?

Is there a way to retrieve body asynchronously with Tornado server from a POST/PUT?

使用 aiohttp 服务器,可以异步 await 请求主体,这样它就可以将手交还给事件循环:

async def post_handler(request):
    data = await request.json()
    return aiohttp.web.Response(status = 201, body = data, content_type='application/json')

但是使用 Tornado 我找不到异步的方法。 取回尸体的唯一方法是:

async def post(self):
    data = self.request.body
    self.write(data)

因此,如果客户端发送大文件,tornado 事件循环将阻塞,直到检索到整个正文,对吗?

不,事件循环没有被阻塞。 post() 不是 运行 直到正文已经完全加载。要逐步处理正文,请参阅 @stream_request_body 装饰器。