python处理文件上传_python – 用于上传和处理文件的uWSGI

我有一个用bottlepy编写的python web应用程序.它的唯一目的是允许人们上传将要处理的大文件(大约需要10-15分钟来处理).

上传代码我很简单:

@route('/upload', method='POST')

def upload_file():

uploadfile = request.files.get('fileToUpload')

if not uploadfile:

abort(500, 'No file selected for upload')

name,ext = os.path.splitext(uploadfile.filename)

if ext not in ['.zip','.gz']:

abort(500, 'File extension not allowed')

try:

uploadfile.save('./files')

process_file(uploadfile.filename) #this function is not yet implemented

return "uploaded file '%s' for processing" % uploadfile.filename

except IOError as e:

abort(409, "File already exists.")

我计划使用uWSGI部署这个应用程序(但是,如果其他技术更好用于此目的,它不是一成不变的.

因此,我对uWSGI用于此目的有一些疑问:

>如果文件上传需要几分钟,uWSGI如何能够在不阻塞的情况下处理其他客户端?

>有没有办法可以使用uWSGI中的内置功能卸载处理,以便用户在上传后获得响应并查询处理状态?

感谢您的任何帮助.

解决方法:

If the file upload takes minutes, how will uWSGI be capable of

handling other clients without blocking?

它会阻止.

解决方案是将类似NGINX的Web服务器放在uWSGI前面,以预先缓冲POST请求.因此,文件上传实际上将绑定到NGINX处理程序,直到完成,然后传递给uWSGI处理程序.

Is there any way the processing can be offloaded using built in

functionality in uWSGI so that the user get a response after upload

and can query for processing status?

您需要创建一个任务队列系统来从Web处理程序卸载处理.

这是一种常见的最佳做法.只需环顾四周的python任务队列.

对于内置功能,它实际上取决于您需要卸载的任务.

您可以使用内置uWSGI spooler或uWSGI mules.

这些是典型任务队列(如非常着名的Celery)的非常好的替代方案,但有局限性.

在您的场景中亲自尝试一下.

标签:bottle,python,uwsgi

来源: https://codeday.me/bug/20190725/1533453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值