# Buggy code
def process_inet(self, file, family, type_, inodes, filter_pid=None):
    """Parse /proc/net/tcp* and /proc/net/udp* files."""
    if file.endswith("6") and not os.path.exists(file):
        # IPv6 not supported
        return
    with open(file, "rt") as f:
        f.readline()  # skip the first line
        for line in f:
            try:
                _, laddr, raddr, status, _, _, _, _, _, inode = line.split()[:10]
            except ValueError:
                raise RuntimeError(
                    "error while parsing %s; malformed line %r" % (file, line)
                )
            if inode in inodes:
                # # We assume inet sockets are unique, so we error
                # # out if there are multiple references to the
                # # same inode. We won't do this for UNIX sockets.
                # if len(inodes[inode]) > 1 and family != socket.AF_UNIX:
                #     raise ValueError("ambiguos inode with multiple "
                #                      "PIDs references")
                pid, fd = inodes[inode][0]
            else:
                pid, fd = None, -1
            if filter_pid is not None and filter_pid != pid:
                continue
            else:
                if type_ == socket.SOCK_STREAM:
                    status = TCP_STATUSES[status]
                else:
                    status = _common.CONN_NONE
                laddr = self.decode_address(laddr, family)
                raddr = self.decode_address(raddr, family)
                yield (fd, family, type_, laddr, raddr, status, pid)


# Traceback (UnicodeDecodeError)
NVIM detected
Retreived terminal pid 13109, nvim should be one of its children
proc name rxvt-unicode with 5 children
child name &amp; pid rxvt-unicode/13110
child name &amp; pid zsh/13111
child name &amp; pid nvim/13272
Could not find neovim socket 'utf-8' codec can't decode byte 0xd7 in position 469: invalid continuation byte
Traceback (most recent call last):
File "/home/teto/.i3/i3nvim.py", line 56, in get_nvim_socket
unix_sockets = child.connections(kind="unix")
File "/home/teto/.local/lib/python3.4/site-packages/psutil/__init__.py", line 1010, in connections
return self._proc.connections(kind)
File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 709, in wrapper
return fun(self, *args, **kwargs)
File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 1169, in connections
ret = _connections.retrieve(kind, self.pid)
File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 555, in retrieve
for fd, family, type_, laddr, raddr, status, bound_pid in ls:
File "/home/teto/.local/lib/python3.4/site-packages/psutil/_pslinux.py", line 508, in process_unix
f.readline()  # skip the first line
File "/usr/lib/python3.4/codecs.py", line 319, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd7 in position 469: invalid continuation byte

# Fixed code
def process_inet(self, file, family, type_, inodes, filter_pid=None):
    """Parse /proc/net/tcp* and /proc/net/udp* files."""
    if file.endswith("6") and not os.path.exists(file):
        # IPv6 not supported
        return
    kw = dict(encoding=DEFAULT_ENCODING) if PY3 else dict()
    with open(file, "rt", **kw) as f:
        f.readline()  # skip the first line
        for line in f:
            try:
                _, laddr, raddr, status, _, _, _, _, _, inode = line.split()[:10]
            except ValueError:
                raise RuntimeError(
                    "error while parsing %s; malformed line %r" % (file, line)
                )
            if inode in inodes:
                # # We assume inet sockets are unique, so we error
                # # out if there are multiple references to the
                # # same inode. We won't do this for UNIX sockets.
                # if len(inodes[inode]) > 1 and family != socket.AF_UNIX:
                #     raise ValueError("ambiguos inode with multiple "
                #                      "PIDs references")
                pid, fd = inodes[inode][0]
            else:
                pid, fd = None, -1
            if filter_pid is not None and filter_pid != pid:
                continue
            else:
                if type_ == socket.SOCK_STREAM:
                    status = TCP_STATUSES[status]
                else:
                    status = _common.CONN_NONE
                laddr = self.decode_address(laddr, family)
                raddr = self.decode_address(raddr, family)
                yield (fd, family, type_, laddr, raddr, status, pid)