龙卷风AsyncHTTPClient获取回调:额外的参数? [英] Tornado AsyncHTTPClient fetch callback: Extra parameters?

查看:236
本文介绍了龙卷风AsyncHTTPClient获取回调:额外的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是那种新的这个整场比赛异步(主要是一个Django的家伙),但我想知道:我怎么能额外的参数传递到龙卷风的AsyncHTTPClient.fetch回调?例如,我要跟踪的次回调已经叫号(为了等到一定数目的数据工作之前执行),我想要做的是这样的:

 高清GETPAGE(个体经营,项目,迭代):
    HTTP = AsyncHTTPClient()
    http.fetch(饲料,回调= self.resp(项目迭代))
高清RESP(个体经营,对此,项目迭代):
    #做东西
    self.finish()


解决方案

您需要在绑定你的额外的参数。
使用functools.partial,像这样的:

 项目= ..
迭代= ..
CB = functools.partial(self.resp,物品,迭代)

或者你可以使用拉姆达,像这样的:

  CB =拉姆达:self.resp(物品,迭代)

(你可能需要将签名添加到高清RESP(个体经营,项目,迭代,响应):)

I'm sort of new to this whole async game (mostly been a Django guy), but I was wondering: how can I pass extra parameters to Tornado's AsyncHTTPClient.fetch callback? For example, I'm tracking the number of times a callback has been called (in order to wait until a certain number have executed before working on the data), and I'd like to do something like:

def getPage(self, items,iteration):
    http = AsyncHTTPClient()    
    http.fetch(feed, callback=self.resp(items,iteration))
def resp(self, response, items, iteration):
    #do stuff
    self.finish()

解决方案

You need to "bind" your additional arguments. Use functools.partial, like this:

items = ..
iteration = ..
cb = functools.partial(self.resp, items, iteration)

or you could use lambda, like this:

cb = lambda : self.resp(items, iteration)

(you probably need to add the signature to def resp(self, items, iteration, response):)

这篇关于龙卷风AsyncHTTPClient获取回调:额外的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆