如何延迟uwsgi中的start_response?

时间:2014-08-22 19:16:59

标签: 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

那么,如何在POST请求完成之前延迟start_response的结果?

1 个答案:

答案 0 :(得分:2)

继续并阻止线程 - 只需启动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