def docker_container_name(container_id, default, cache=dict()):
    # Python's default arguments are evaluated when the function is
    # defined, not when the function is called.
    # We potentially cache and return a default value so we don't spend time
    # pointlessly retrying to get the container name if something goes wrong.
    cached_name = cache.get(container_id)
    if cached_name:
        return cached_name

    try:
        sp = subprocess.Popen(['docker', 'inspect', container_id],
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
    except __HOLE__:
        # `docker` is not on PATH
        cache[container_id] = default
        return default

    for _ in range(10):
        sp.poll()
        if sp.returncode is not None:
            break
        time.sleep(0.1)

    if sp.returncode is None:
        try:
            sp.kill()
        except OSError:
            # OSError: [Errno 3] No such process
            pass
    elif sp.returncode == 0:
        stdout, _stderr = sp.communicate()
        try:
            containers = json.loads(stdout)
            if len(containers) == 1:
                container = containers[0]
                container_name = container['Name'].lstrip('/')
                name = '/docker/' + container_name
                cache[container_id] = name
                return name
        except Exception:
            pass

    cache[container_id] = default
    return default
dataset/ETHPy150Open yadutaf/ctop/cgroup_top.py/docker_container_name