# Buggy code
def _find_worker(relative, follow, done, work, results, errors):
    """Worker thread for collecting stat() results.

    :param str relative: directory to make results relative to
    :param bool follow: if symlinks should be followed
    :param threading.Event done: event indicating that all work has been done
    :param queue.Queue work: queue of paths to process
    :param dict results: shared dictionary for storing all the stat() results
    :param dict errors: shared dictionary for storing any per path errors
    """
    while not done.is_set():
        try:
            entry, parents = work.get(block=False)
        except queue.Empty:
            continue

        if relative:
            path = os.path.relpath(entry, relative)
        else:
            path = entry

        try:
            if follow:
                st = os.stat(entry)
            else:
                st = os.lstat(entry)

            if (st.st_dev, st.st_ino) in parents:
                errors[path] = exceptions.FindError("Sym/hardlink loop found.")
                continue

            parents = parents + [(st.st_dev, st.st_ino)]
            if stat.S_ISDIR(st.st_mode):
                for e in os.listdir(entry):
                    work.put((os.path.join(entry, e), parents))
            elif stat.S_ISREG(st.st_mode):
                results[path] = st
            elif stat.S_ISLNK(st.st_mode):
                errors[path] = exceptions.FindError("Not following symlinks.")
            else:
                errors[path] = exceptions.FindError("Not a file or directory.")

        except OSError as e:
            errors[path] = exceptions.FindError(e.strerror, e.errno)
        finally:
            work.task_done()


# Traceback (UnicodeDecodeError)
2015-02-04 06:30:11,901 ERROR [3714:MpdSession-27] pykka: Unhandled exception in MpdSession (urn:uuid:9595028c-486c-4c89-813a-785c3cafc057):
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 200, in _actor_loop
response = self._handle_receive(message)
File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 303, in _handle_receive
return self.on_receive(message)
File "/usr/lib/python2.7/dist-packages/mopidy/utils/network.py", line 366, in on_receive
self.on_line_received(line)
File "/usr/lib/python2.7/dist-packages/mopidy/mpd/session.py", line 41, in on_line_received
self.send_lines(response)
File "/usr/lib/python2.7/dist-packages/mopidy/utils/network.py", line 428, in send_lines
self.connection.queue_send(self.encode(data))
File "/usr/lib/python2.7/dist-packages/mopidy/utils/network.py", line 189, in queue_send
self.send_buffer = self.send(self.send_buffer + data)
File "/usr/lib/python2.7/dist-packages/mopidy/utils/network.py", line 202, in send
self.stop('Unexpected client error: %s' % e)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)

# Fixed code
def _find_worker(relative, follow, done, work, results, errors):
    """Worker thread for collecting stat() results.

    :param str relative: directory to make results relative to
    :param bool follow: if symlinks should be followed
    :param threading.Event done: event indicating that all work has been done
    :param queue.Queue work: queue of paths to process
    :param dict results: shared dictionary for storing all the stat() results
    :param dict errors: shared dictionary for storing any per path errors
    """
    while not done.is_set():
        try:
            entry, parents = work.get(block=False)
        except queue.Empty:
            continue

        if relative:
            path = os.path.relpath(entry, relative)
        else:
            path = entry

        try:
            if follow:
                st = os.stat(entry)
            else:
                st = os.lstat(entry)

            if (st.st_dev, st.st_ino) in parents:
                errors[path] = exceptions.FindError("Sym/hardlink loop found.")
                continue

            parents = parents + [(st.st_dev, st.st_ino)]
            if stat.S_ISDIR(st.st_mode):
                for e in os.listdir(entry):
                    work.put((os.path.join(entry, e), parents))
            elif stat.S_ISREG(st.st_mode):
                results[path] = st
            elif stat.S_ISLNK(st.st_mode):
                errors[path] = exceptions.FindError("Not following symlinks.")
            else:
                errors[path] = exceptions.FindError("Not a file or directory.")

        except OSError as e:
            errors[path] = exceptions.FindError(
                encoding.locale_decode(e.strerror), e.errno
            )
        finally:
            work.task_done()