Exemple #1
0
    def memcache(self, f):
        name = _fullname(f)
        cache = self.load_memcache(name)

        @wraps(f)
        def memcached(*args):
            """Cache the function in memory."""
            # The arguments need to be hashable. Much faster than using hash().
            h = args
            out = cache.get(h, None)
            if out is None:
                out = f(*args)
                cache[h] = out
            return out
        return memcached
Exemple #2
0
def load_cli_plugins(cli, config_dir=None):
    """Load all plugins and attach them to a CLI object."""
    from .config import load_master_config

    config = load_master_config(config_dir=config_dir)
    plugins = discover_plugins(config.Plugins.dirs)

    for plugin in plugins:
        if not hasattr(plugin, 'attach_to_cli'):  # pragma: no cover
            continue
        logger.debug("Attach plugin `%s` to CLI.", _fullname(plugin))
        # NOTE: plugin is a class, so we need to instantiate it.
        try:
            plugin().attach_to_cli(cli)
        except Exception as e:  # pragma: no cover
            logger.error("Error when loading plugin `%s`: %s", plugin, e)
Exemple #3
0
    def memcache(self, f):
        name = _fullname(f)
        cache = self.load_memcache(name)

        @wraps(f)
        def memcached(*args):
            """Cache the function in memory."""
            # The arguments need to be hashable. Much faster than using hash().
            h = args
            out = cache.get(h, None)
            if out is None:
                out = f(*args)
                cache[h] = out
            return out

        return memcached
Exemple #4
0
    def memcache(self, f):
        from joblib import hash
        name = _fullname(f)
        cache = self.load_memcache(name)

        @wraps(f)
        def memcached(*args, **kwargs):
            """Cache the function in memory."""
            h = hash((args, kwargs))
            if h in cache:
                # logger.debug("Get %s(%s) from memcache.", name, str(args))
                return cache[h]
            else:
                # logger.debug("Compute %s(%s).", name, str(args))
                out = f(*args, **kwargs)
                cache[h] = out
                return out
        return memcached
Exemple #5
0
    def memcache(self, f):
        from joblib import hash
        name = _fullname(f)
        cache = self.load_memcache(name)

        @wraps(f)
        def memcached(*args, **kwargs):
            """Cache the function in memory."""
            h = hash((args, kwargs))
            if h in cache:
                # logger.debug("Get %s(%s) from memcache.", name, str(args))
                return cache[h]
            else:
                # logger.debug("Compute %s(%s).", name, str(args))
                out = f(*args, **kwargs)
                cache[h] = out
                return out

        return memcached