相关疑难解决方法(0)

如何异步地将瓶子响应给客户端?

Flask是一个单线程Web服务器.但我想让它在处理一些耗时的请求时不会阻塞.

例如:

from flask import Flask
import time
import sys
app = Flask(__name__)

@app.route("/")
def hello():
    print "request"
    sys.stdout.flush()
    for _ in range(10000000):
        for j in range(10000000):
            i = 1
    return "Hello World!"

if __name__ == "__main__":
    app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)

我希望当每个客户端请求服务器时,它总是立即在控制台上输出"请求".我试过gunicorn并运行gunicorn -k gevent -w 4 a:app但它仍然显示同步.

python flask gunicorn

10
推荐指数
1
解决办法
2万
查看次数

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.")
Run Code Online (Sandbox Code Playgroud)

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

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

  1. 如果文件上传需要几分钟,那么uWSGI如何能够在不阻塞的情况下处理其他客户端?
  2. 是否有任何方法可以使用uWSGI中的内置功能卸载处理,以便用户在上载后获得响应并可以查询处理状态?

感谢您的任何帮助.

python bottle uwsgi

3
推荐指数
1
解决办法
4199
查看次数

标签 统计

python ×2

bottle ×1

flask ×1

gunicorn ×1

uwsgi ×1