gpt4 book ai didi

python - 如何延迟 uwsgi 中的 start_response?

转载 作者:行者123 更新时间:2023-11-28 17:40:10 27 4
gpt4 key购买 nike

我想做以下事情:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com