utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:python-hnvclient 作者: openstack 项目源码 文件源码
def run_once(function, state={}, errors={}):
    """A memoization decorator, whose purpose is to cache calls."""
    @six.wraps(function)
    def _wrapper(*args, **kwargs):
        if function in errors:
            # Deliberate use of LBYL.
            six.reraise(*errors[function])

        try:
            return state[function]
        except KeyError:
            try:
                state[function] = result = function(*args, **kwargs)
                return result
            except Exception:
                errors[function] = sys.exc_info()
                raise
    return _wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号