# Buggy code
def get_docker_io(self, container_id, all_stats):
    """Return the container IO usage using the Docker API (v1.0 or higher).

    Input: id is the full container id
    Output: a dict {'time_since_update': 3000, 'ior': 10, 'iow': 65}.
    with:
        time_since_update: number of seconds elapsed between the latest grab
        ior: Number of byte readed
        iow: Number of byte written
    """
    # Init the returned dict
    io_new = {}

    # Read the ior/iow stats (in bytes)
    try:
        iocounters = all_stats["blkio_stats"]
    except KeyError as e:
        # all_stats do not have io information
        logger.debug(
            "Can not grab block IO usage for container {0} ({1})".format(
                container_id, e
            )
        )
        # No fallback available...
        return io_new

    # Previous io interface stats are stored in the io_old variable
    if not hasattr(self, "iocounters_old"):
        # First call, we init the io_old var
        self.iocounters_old = {}
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass

    if container_id not in self.iocounters_old:
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass
    else:
        # By storing time data we enable IoR/s and IoW/s calculations in the
        # XML/RPC API, which would otherwise be overly difficult work
        # for users of the API
        try:
            # Read IOR and IOW value in the structure list of dict
            ior = [
                i for i in iocounters["io_service_bytes_recursive"] if i["op"] == "Read"
            ][0]["value"]
            iow = [
                i
                for i in iocounters["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
            ior_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Read"
            ][0]["value"]
            iow_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
        except (IndexError, KeyError) as e:
            # all_stats do not have io information
            logger.debug(
                "Can not grab block IO usage for container {0} ({1})".format(
                    container_id, e
                )
            )
        else:
            io_new["time_since_update"] = getTimeSinceLastUpdate(
                "docker_io_{0}".format(container_id)
            )
            io_new["ior"] = ior - ior_old
            io_new["iow"] = iow - iow_old
            io_new["cumulative_ior"] = ior
            io_new["cumulative_iow"] = iow

            # Save stats to compute next bitrate
            self.iocounters_old[container_id] = iocounters

    # Return the stats
    return io_new


# Traceback (TypeError)
$ glances
Traceback (most recent call last):
File "/usr/local/bin/glances", line 9, in <module>
load_entry_point('Glances==2.6.1', 'console_scripts', 'glances')()
File "/usr/local/lib/python3.4/dist-packages/glances/__init__.py", line 133, in main
standalone.serve_forever()
File "/usr/local/lib/python3.4/dist-packages/glances/standalone.py", line 107, in serve_forever
return self.__serve_forever()
File "/usr/local/lib/python3.4/dist-packages/glances/standalone.py", line 88, in __serve_forever
self.stats.update()
File "/usr/local/lib/python3.4/dist-packages/glances/stats.py", line 154, in update
self._plugins[p].update()
File "/usr/local/lib/python3.4/dist-packages/glances/plugins/glances_plugin.py", line 658, in wrapper
ret = fct(*args, **kw)
File "/usr/local/lib/python3.4/dist-packages/glances/plugins/glances_docker.py", line 226, in update
container['memory'] = self.get_docker_memory(container['Id'], self.thread_list[container['Id']].stats)
File "/usr/local/lib/python3.4/dist-packages/glances/plugins/glances_docker.py", line 297, in get_docker_memory
ret['rss'] = all_stats['memory_stats']['stats']['rss']
TypeError: 'NoneType' object is not subscriptable

# Fixed code
def get_docker_io(self, container_id, all_stats):
    """Return the container IO usage using the Docker API (v1.0 or higher).

    Input: id is the full container id
    Output: a dict {'time_since_update': 3000, 'ior': 10, 'iow': 65}.
    with:
        time_since_update: number of seconds elapsed between the latest grab
        ior: Number of byte readed
        iow: Number of byte written
    """
    # Init the returned dict
    io_new = {}

    # Read the ior/iow stats (in bytes)
    try:
        iocounters = all_stats["blkio_stats"]
    except KeyError as e:
        # all_stats do not have io information
        logger.debug(
            "Can not grab block IO usage for container {0} ({1})".format(
                container_id, e
            )
        )
        logger.debug(all_stats)
        # No fallback available...
        return io_new

    # Previous io interface stats are stored in the io_old variable
    if not hasattr(self, "iocounters_old"):
        # First call, we init the io_old var
        self.iocounters_old = {}
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass

    if container_id not in self.iocounters_old:
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass
    else:
        # By storing time data we enable IoR/s and IoW/s calculations in the
        # XML/RPC API, which would otherwise be overly difficult work
        # for users of the API
        try:
            # Read IOR and IOW value in the structure list of dict
            ior = [
                i for i in iocounters["io_service_bytes_recursive"] if i["op"] == "Read"
            ][0]["value"]
            iow = [
                i
                for i in iocounters["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
            ior_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Read"
            ][0]["value"]
            iow_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
        except (IndexError, KeyError) as e:
            # all_stats do not have io information
            logger.debug(
                "Can not grab block IO usage for container {0} ({1})".format(
                    container_id, e
                )
            )
        else:
            io_new["time_since_update"] = getTimeSinceLastUpdate(
                "docker_io_{0}".format(container_id)
            )
            io_new["ior"] = ior - ior_old
            io_new["iow"] = iow - iow_old
            io_new["cumulative_ior"] = ior
            io_new["cumulative_iow"] = iow

            # Save stats to compute next bitrate
            self.iocounters_old[container_id] = iocounters

    # Return the stats
    return io_new