# Buggy code
def get_weight(self):
    """Return "weight" of a process and all its children for sorting."""
    if self.sort_key == "name":
        return self.stats[self.sort_key]

    # sum ressource usage for self and children
    total = 0
    nodes_to_sum = collections.deque([self])
    while nodes_to_sum:
        current_node = nodes_to_sum.pop()
        if callable(self.sort_key):
            total += self.sort_key(current_node.stats)
        elif self.sort_key == "io_counters":
            stats = current_node.stats[self.sort_key]
            total += stats[0] - stats[2] + stats[1] - stats[3]
        else:
            total += current_node.stats[self.sort_key]
        nodes_to_sum.extend(current_node.children)

    return total


# Traceback (TypeError)
Traceback (most recent call last):
File "~/venvs/py34-glances/bin/glances", line 9, in <module>
load_entry_point('Glances==2.2-BETA', 'console_scripts', 'glances')()
File "~/venvs/py34-glances/src/glances/glances/__init__.py", line 121, in main
standalone.serve_forever()
File "~/venvs/py34-glances/src/glances/glances/core/glances_standalone.py", line 81, in serve_forever
self.screen.update(self.stats)
File "~/venvs/py34-glances/src/glances/glances/outputs/glances_curses.py", line 785, in update
self.flush(stats, cs_status=cs_status)
File "~/venvs/py34-glances/src/glances/glances/outputs/glances_curses.py", line 751, in flush
self.display(stats, cs_status=cs_status)
File "~/venvs/py34-glances/src/glances/glances/outputs/glances_curses.py", line 448, in display
'processlist').get_stats_display(args=self.args)
File "~/venvs/py34-glances/src/glances/glances/plugins/glances_plugin.py", line 398, in get_stats_display
'msgdict': self.msg_curse(args),
File "~/venvs/py34-glances/src/glances/glances/plugins/glances_processlist.py", line 401, in msg_curse
max_node_count=glances_processes.get_max_processes()))
File "~/venvs/py34-glances/src/glances/glances/plugins/glances_processlist.py", line 78, in get_process_tree_curses_data
for child in node.iter_children():
File "~/venvs/py34-glances/src/glances/glances/core/glances_processes.py", line 140, in iter_children
self.children.sort(key=self.__class__.get_weight, reverse=self.reverse_sorting)
File "~/venvs/py34-glances/src/glances/glances/core/glances_processes.py", line 100, in get_weight
total += current_node.stats[self.sort_key]
TypeError: unsupported operand type(s) for +=: 'int' and 'pcputimes'

# Fixed code
def get_weight(self):
    """Return "weight" of a process and all its children for sorting."""
    if self.sort_key == "name":
        return self.stats[self.sort_key]

    # sum ressource usage for self and children
    total = 0
    nodes_to_sum = collections.deque([self])
    while nodes_to_sum:
        current_node = nodes_to_sum.pop()
        if callable(self.sort_key):
            total += self.sort_key(current_node.stats)
        elif self.sort_key == "io_counters":
            stats = current_node.stats[self.sort_key]
            total += stats[0] - stats[2] + stats[1] - stats[3]
        elif self.sort_key == "cpu_times":
            total += sum(current_node.stats[self.sort_key])
        else:
            total += current_node.stats[self.sort_key]
        nodes_to_sum.extend(current_node.children)

    return total