0
我试图开发Web应用程序中使用烧瓶,下面是我的代码,瓶:服务器未响应内部API访问
from sample import APIAccessor
#API
@app.route('/test/triggerSecCall',methods=['GET'])
def triggerMain():
resp = APIAccessor().trigger2()
return Response(json.dumps(resp), mimetype='application/json')
@app.route('/test/seccall',methods=['GET'])
def triggerSub():
resp = {'data':'called second method'}
return Response(json.dumps(resp), mimetype='application/json')
我的触发方式,包含下面的代码,
def trigger2(self):
url = 'http:/127.0.0.1:5000/test/seccall'
response = requests.get(url)
response.raise_for_status()
responseJson = response.json()
if self.track:
print 'Response:::%s' %str(responseJson)
return responseJson
当我打到http://127.0.0.1:5000/test/seccall
,我得到了预期的输出。当我点击/test/triggerSecCall
时,服务器停止响应。请求永远等待。 在此阶段,我无法从任何其他REST客户端访问任何apis。当我强制停止服务器(Ctrl + C)时,我在second
REST客户端中得到响应。
为什么烧瓶不能服务于内部服务电话?
是的!我输入相同的东西。更多信息可以在这里找到:https://stackoverflow.com/questions/38876721/handle-flask-requests-concurrently-with-threaded-true – MacMcIrish
谢谢你克劳斯和MacMaclirish。我认为让我的应用程序在多个线程中运行将解决我的问题。这只是一个简单的应用程序,将被少数人使用。 – Kajal
那么,这将是一个多线程运行服务器的解决方案,但这只是掩盖了潜在的问题。如果您的Web应用程序不在一个线程中运行,则会出现问题。多线程也会使调试复杂化。 –