python - 如何延迟 uwsgi 中的 start_response?

标签 python wsgi uwsgi

我想做以下事情:

r = requests.post('https://foo.com/test', data=json.dumps(fields), headers=headers)
if r.status_code != requests.codes.ok:
    start_response(str(r.status_code) + ' ' + r.reason, [('Content-Type', 'text/plain')])
    body.put(r.reason)
else:
    start_response('200 OK', [('Content-Type', 'application/json')])
    body.put(r.json())

但是这个调用会阻塞主线程,所以我这样做:

body = queue.Queue()
gevent.spawn(make_request, environ, start_response, body)

但现在我收到错误SystemError: you can call uwsgi api function only from the main callable

那么,如何将 start_response 的结果延迟到 POST 请求完成之后呢?

最佳答案

继续阻塞线程 —— 只用其中的几个来启动 uWSGI:

uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2

来自 https://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html#adding-concurrency-and-monitoring

关于python - 如何延迟 uwsgi 中的 start_response?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25454095/

相关文章:

python - (Flask) 伪造 request.environ ['REMOTE_USER' ] 用于测试

django - nginx,uwsgi,DJango,DEBUG = False时的502, “upstream prematurely closed connection”

python - uWSGI 在达到生命周期时重置工作人员导致停机

Python:字典和按字母顺序排序

python - AWS CLI/Boto3 Cloudsearch 验证冲突

python - 用于 OAuth 身份验证的 WSGI 中间件

django - 在mac上安装uWSGI时出错

python - 下载 twitch.tv 流的第一帧

python - 使用 Requests 2.3.0 避免空 block 的 ChunkedEncodingError

python - 如何在共享内存中轻松存储python可用的只读数据结构