# Buggy code
def serve(config, options=None):
    """
    Start the devserver, and rebuild the docs whenever any changes take effect.
    """
    # Create a temporary build directory, and set some options to serve it
    tempdir = tempfile.mkdtemp()
    options["site_dir"] = tempdir

    # Only use user-friendly URLs when running the live server
    options["use_directory_urls"] = True

    # Perform the initial build
    config = load_config(options=options)
    build(config, live_server=True)

    # Note: We pass any command-line options through so that we
    #       can re-apply them if the config file is reloaded.
    event_handler = BuildEventHandler(options)
    config_event_handler = ConfigEventHandler(options)

    # We could have used `Observer()`, which can be faster, but
    # `PollingObserver()` works more universally.
    observer = PollingObserver()
    observer.schedule(event_handler, config["docs_dir"], recursive=True)
    for theme_dir in config["theme_dir"]:
        observer.schedule(event_handler, theme_dir, recursive=True)
    observer.schedule(config_event_handler, ".")
    observer.start()

    class TCPServer(socketserver.TCPServer):
        allow_reuse_address = True

    class DocsDirectoryHandler(FixedDirectoryHandler):
        base_dir = config["site_dir"]

    host, port = config["dev_addr"].split(":", 1)
    server = TCPServer((host, int(port)), DocsDirectoryHandler)

    print("Running at: http://%s:%s/" % (host, port))
    print("Live reload enabled.")
    print("Hold ctrl+c to quit.")
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print("Stopping server...")

    # Clean up
    observer.stop()
    observer.join()
    shutil.rmtree(tempdir)
    print("Quit complete")


# Traceback (OSError)
Traceback (most recent call last):
File "/home/pi/.virtualenvs/face/bin/mkdocs", line 9, in <module>
load_entry_point('mkdocs==0.11.1', 'console_scripts', 'mkdocs')()
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/mkdocs/main.py", line 60, in run_main
main(cmd, args=sys.argv[2:], options=dict(opts))
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/mkdocs/main.py", line 33, in main
serve(config, options=options)
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/mkdocs/serve.py", line 96, in serve
observer.start()
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/observers/api.py", line 255, in start
emitter.start()
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/utils/__init__.py", line 111, in start
self.on_thread_start()
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/observers/polling.py", line 77, in on_thread_start
self._snapshot = self._take_snapshot()
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/observers/polling.py", line 74, in <lambda>
self.watch.path, self.watch.is_recursive, stat=stat, listdir=listdir)
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/utils/dirsnapshot.py", line 207, in __init__
st = stat(path)
OSError: [Errno 2] No such file or directory: '/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/mkdocs/themes/face'
Exception in thread Thread-3 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/observers/api.py", line 146, in run
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/observers/polling.py", line 91, in queue_events
File "/home/pi/.virtualenvs/face/local/lib/python2.7/site-packages/watchdog/observers/polling.py", line 74, in <lambda>
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

# Fixed code
def serve(config, options=None):
    """
    Start the devserver, and rebuild the docs whenever any changes take effect.
    """
    # Create a temporary build directory, and set some options to serve it
    tempdir = tempfile.mkdtemp()
    options["site_dir"] = tempdir

    # Only use user-friendly URLs when running the live server
    options["use_directory_urls"] = True

    # Perform the initial build
    config = load_config(options=options)
    build(config, live_server=True)

    # Note: We pass any command-line options through so that we
    #       can re-apply them if the config file is reloaded.
    event_handler = BuildEventHandler(options)
    config_event_handler = ConfigEventHandler(options)

    # We could have used `Observer()`, which can be faster, but
    # `PollingObserver()` works more universally.
    observer = PollingObserver()
    observer.schedule(event_handler, config["docs_dir"], recursive=True)
    for theme_dir in config["theme_dir"]:
        if not os.path.exists(theme_dir):
            continue
        observer.schedule(event_handler, theme_dir, recursive=True)
    observer.schedule(config_event_handler, ".")
    observer.start()

    class TCPServer(socketserver.TCPServer):
        allow_reuse_address = True

    class DocsDirectoryHandler(FixedDirectoryHandler):
        base_dir = config["site_dir"]

    host, port = config["dev_addr"].split(":", 1)
    server = TCPServer((host, int(port)), DocsDirectoryHandler)

    print("Running at: http://%s:%s/" % (host, port))
    print("Live reload enabled.")
    print("Hold ctrl+c to quit.")
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print("Stopping server...")

    # Clean up
    observer.stop()
    observer.join()
    shutil.rmtree(tempdir)
    print("Quit complete")