import tornado.ioloop
from tornado.httpclient import AsyncHTTPClient
import functools
def fetch():
response = yield functools.partial(AsyncHTTPClient().fetch, 'http://jinri.info')
print response
gen = fetch()
f = gen.next()
def callback(response):
try:
gen.send(response)
except StopIteration:
pass
f(callback)
print 'here'
tornado.ioloop.IOLoop.instance().start()
- 为什么
f(acllback)
在print 'here'
之后执行 -
tornado.ioloop.IOLoop.instance().start()
这行代码的作用什么? - 用debug看程序运行的流程,在执行了
tornado.ioloop.IOLoop.instance().start()
之后,response才有结果,然后执行callback()
回调,这个执行顺序也不是特别明白
在学习异步调用 看这代码卡主了.... 麻烦大家帮我解答下
这段code的执行过程:
tornado.ioloop.IOLoop.instance().start()
是tornado
开启网络listen
的主循环