# Buggy code
def _livereload(host, port, config, builder, site_dir):
    # We are importing here for anyone that has issues with livereload. Even if
    # this fails, the --no-livereload alternative should still work.
    from livereload import Server
    import livereload.handlers

    class LiveReloadServer(Server):
        def get_web_handlers(self, script):
            handlers = super(LiveReloadServer, self).get_web_handlers(script)
            # replace livereload handler
            return [
                (
                    handlers[0][0],
                    _get_handler(site_dir, livereload.handlers.StaticFileHandler),
                    handlers[0][2],
                )
            ]

    server = LiveReloadServer()

    # Watch the documentation files, the config file and the theme files.
    server.watch(config["docs_dir"], builder)
    server.watch(config["config_file_path"], builder)

    for d in config["theme"].dirs:
        server.watch(d, builder)

    # Run `serve` plugin events.
    server = config["plugins"].run_event("serve", server, config=config)

    server.serve(root=site_dir, host=host, port=port, restart_delay=0)


# Traceback (NotImplementedError)
C:\dev\testing
λ  mkdocs serve
INFO    -  Building documentation...
INFO    -  Cleaning site directory
[I 191017 14:49:48 server:296] Serving on http://127.0.0.1:8000
Traceback (most recent call last):
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\aleksandr.skobelev\AppData\Local\Programs\Python\Python38\Scripts\mkdocs.exe\__main__.py", line 9, in <module>
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\mkdocs\__main__.py", line 128, in serve_command
serve.serve(
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\mkdocs\commands\serve.py", line 124, in serve
_livereload(host, port, config, builder, site_dir)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\mkdocs\commands\serve.py", line 58, in _livereload
server.serve(root=site_dir, host=host, port=port, restart_delay=0)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\livereload\server.py", line 298, in serve
self.application(
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\livereload\server.py", line 253, in application
app.listen(port, address=host)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\tornado\web.py", line 2112, in listen
server.listen(port, address)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\tornado\tcpserver.py", line 152, in listen
self.add_sockets(sockets)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
self._handlers[sock.fileno()] = add_accept_handler(
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "c:\users\aleksandr.skobelev\appdata\local\programs\python\python38\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError

# Fixed code
def _livereload(host, port, config, builder, site_dir):
    # We are importing here for anyone that has issues with livereload. Even if
    # this fails, the --no-livereload alternative should still work.
    _init_asyncio_patch()
    from livereload import Server
    import livereload.handlers

    class LiveReloadServer(Server):
        def get_web_handlers(self, script):
            handlers = super(LiveReloadServer, self).get_web_handlers(script)
            # replace livereload handler
            return [
                (
                    handlers[0][0],
                    _get_handler(site_dir, livereload.handlers.StaticFileHandler),
                    handlers[0][2],
                )
            ]

    server = LiveReloadServer()

    # Watch the documentation files, the config file and the theme files.
    server.watch(config["docs_dir"], builder)
    server.watch(config["config_file_path"], builder)

    for d in config["theme"].dirs:
        server.watch(d, builder)

    # Run `serve` plugin events.
    server = config["plugins"].run_event("serve", server, config=config)

    server.serve(root=site_dir, host=host, port=port, restart_delay=0)