How to delay start_response in uwsgi?
I want to do the following:
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())
But the call is blocking the main thread, so I do:
body = queue.Queue() gevent.spawn(make_request, environ, start_response, body)
but now i am getting error SystemError: you can call uwsgi api function only from the main callable
So how can I delay the start_response result until the POST request is complete?
+3
source to share
1 answer
Go ahead and block the thread - just run uWSGI with a few of them:
uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2
from https://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html#adding-concurrency-and-monitoring
+2
source to share