繁体   English   中英

Visual Studio Code 和 Azure 中的异步 python 函数

[英]Asynchronous python functions in Visual Studio Code and Azure

我正在使用 Visual Studio Code 和 python 创建 Azure function。 一旦用户传入参数,我需要 function 立即返回 http 204 代码(成功)。 在最初的 204 响应之后,我需要 function 继续处理直到完成。 不再需要 http 响应。

一般项目结构如下:

def process():
   # do stuff


def main(req: func.HttpRequest) -> func.HttpResponse:
   return func.HttpResponse(status_code=204)
   # run process() function

代码按此顺序运行非常重要。 process() 方法需要 5 到 10 分钟才能运行,但我的客户的 API 需要 function 立即响应,说“处理已成功开始”。 再一次,在初始立即 204 之后不再需要 http 代码/响应。

我曾尝试使用 python 的asyncio库,但到目前为止还没有发现任何对我的情况有帮助的东西。 我也尝试过没有解决方案的瓶子框架。

您可能想看看 Durable Functions,特别是Async HTTP APIs 模式 此外, 202 Accepted代码看起来更适合您的情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM