我想做以下事情:
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/