# Buggy code
def process_unix(self, file, family, inodes, filter_pid=None):
    """Parse /proc/net/unix files."""
    with open(file, "rt") as f:
        f.readline()  # skip the first line
        for line in f:
            tokens = line.split()
            try:
                _, _, _, _, type_, _, inode = tokens[0:7]
            except ValueError:
                raise RuntimeError(
                    "error while parsing %s; malformed line %r" % (file, line)
                )
            if inode in inodes:
                # With UNIX sockets we can have a single inode
                # referencing many file descriptors.
                pairs = inodes[inode]
            else:
                pairs = [(None, -1)]
            for pid, fd in pairs:
                if filter_pid is not None and filter_pid != pid:
                    continue
                else:
                    if len(tokens) == 8:
                        path = tokens[-1]
                    else:
                        path = ""
                    type_ = int(type_)
                    raddr = None
                    status = _common.CONN_NONE
                    yield (fd, family, type_, path, 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_unix(self, file, family, inodes, filter_pid=None):
    """Parse /proc/net/unix files."""
    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:
            tokens = line.split()
            try:
                _, _, _, _, type_, _, inode = tokens[0:7]
            except ValueError:
                raise RuntimeError(
                    "error while parsing %s; malformed line %r" % (file, line)
                )
            if inode in inodes:
                # With UNIX sockets we can have a single inode
                # referencing many file descriptors.
                pairs = inodes[inode]
            else:
                pairs = [(None, -1)]
            for pid, fd in pairs:
                if filter_pid is not None and filter_pid != pid:
                    continue
                else:
                    if len(tokens) == 8:
                        path = tokens[-1]
                    else:
                        path = ""
                    type_ = int(type_)
                    raddr = None
                    status = _common.CONN_NONE
                    yield (fd, family, type_, path, raddr, status, pid)