from twisted.internet import defer, reactor from twisted.web.client import getPage def response(*args, **kwargs): print('返回页面内容') def callback(*args, **kwargs): print('执行了一个回调', args) @defer.inlineCallbacks def start(url): d = getPage(url.encode('utf-8')) d.addCallback(response) d.addCallback(callback) yield d def stop(*args, **kwargs): print('stop') reactor.stop() urls = [ 'http://www.baidu.com', 'http://www.sina.com', ] li = [] for url in urls: ret = start(url) li.append(ret) print(li) d = defer.DeferredList(li) d.addBoth(stop) reactor.run()
标签:url,demo,args,some,twisted,li,stop,print From: https://www.cnblogs.com/angdh/p/17363807.html