應用引擎異步例如:如何將異步調用從應用引擎移植到龍捲風?
from google.appengine.api import urlfetch
rpc = urlfetch.create_rpc()
urlfetch.make_fetch_call(rpc, "http://www.google.com/")
try:
result = rpc.get_result()
if result.status_code == 200:
text = result.content
# ...
except urlfetch.DownloadError:
raise
return text
如何在龍捲風做到這一點?我試過(使用swirl)的東西,如:
import swirl
http = tornado.httpclient.AsyncHTTPClient()
uri = 'http://www.google.com/'
try:
response = yield lambda cb: http.fetch(uri, cb)
if response.code == 200:
text = result.content
# ...
except tornado.httpclient.HTTPError:
raise
return text
但我得到一個語法錯誤,因爲我不能有回報,在相同功能的產生......