0
我在Tornado中遇到了異步連接的問題。我想通過訪問Flask端點(/ async/...)來製作代理頁面主體。然後它應該異步獲取該頁面的內容。但我該怎麼做呢?有一個我已經寫過的片段。它打印response.body,但我怎樣才能在proxyAsync中返回它以在網頁上顯示它?在Tornado和Flask中同步運行@ gen.coroutine
@gen.coroutine
def fetch_coroutine(url):
http_client = AsyncHTTPClient()
response = yield http_client.fetch(url)
print('------------------')
print(response.body)
print('------------------')
raise gen.Return(response.body)
@proxy_service.route('/async/<path:url>', methods=methodsHTTP)
def proxyAsync(url):
# Send request
response = fetch_coroutine(url)
return jsonify({})