class Get(object):
"""
Lazy value calculate for object
對象的延遲值計算
"""
def __init__(self, getter):
self.getter = getter
def __get__(self, instance, owner):
return self.getter()
kwargs[name] = utils.Get(lambda name=name: connect_message_queue(name, kwargs.get('message_queue'), kwargs['queue_maxsize']))
param = utils.Get(connect_message_queue(name, k1, k2))
connect_message_queue(): 返回Queue
utils.Get()的作用是锦茁,在具體用到param時才去執(zhí)行connect_message_queue()里實現(xiàn)的那部分代碼
kwargs[name] = utils.Get(lambda name=name: connect_message_queue(
name, kwargs.get('message_queue'), kwargs['queue_maxsize']))
ctx.obj = utils.ObjectDict(ctx.obj or {})
ctx.obj['instances'] = []
ctx.obj.update(kwargs)
g = ctx.obj
name = 'status_queue'
app.config['queues'][name] = getattr(g, name, None)
=> ctx.obj['status_queue'] # 在這一部分才執(zhí)行connect_message_queue()里面實現(xiàn)的部分