I'm trying to do http request from one handler to another but it is timing out. Why? Using request library works but not with 127.0.0.1
# sample.py
import falcon
import json
import requests
class TS:
def on_get(self, req, resp):
output = {
'output': 'DataService.',
'author': 'Python3'
}
resp2 = requests.get('http://127.0.0.1:8000/a')
resp.body = json.dumps(output)
resp.status = falcon.HTTP_200
class SE:
def on_get(self, req, resp):
output = {
'output': 'Service.',
'author': 'Python3'
}
resp.body = json.dumps(output)
api = falcon.API()
api.add_route('/a', SE())
api.add_route('/t', TS())
I get this error log
[2017-02-02 20:41:05 +0100] [27515] [CRITICAL] WORKER TIMEOUT (pid:27544)
You're probably running this using gunicorn
from the command line as shown in the tutorial:
$ gunicorn sample:api
That means that gunicorn is started with the default of one worker process which is a sync worker with one thread.
This setup can only handle one request at a time, any further request will block until the previous has completed. So if you try to make a request from within your application to the same server you'll have a deadlock.
For this to work you can increase the number of worker processes and threads, e.g:
$ gunicorn --workers 2 --threads 4 sample:api