在python中在后台返回并处理请求

时间:2020-02-12 07:00:56

标签: python python-3.x api swagger

我有一个函数来处理从招摇传递的文件数据。但是,如果文件大小更大,则响应时间会更长,并且请求超时。

def func():
    file = request.files['fileName']
    file_data = file.read().splitlines()
    <read file and process each line>
    return 'File processed'

现在,我只想返回上传的文件(带有201),然后处理应继续在后台进行。

类似这样的东西:

def func():
    try:
       file = request.files['fileName']
       file_data = file.read().splitlines()
       if file_data:
          return "File uploaded successfully"
     finally:
        <read file and process each line>

这是我正在尝试的事情。

我能得到一些建议吗,或者是否有比这更好的解决方案。 谢谢!

0 个答案:

没有答案