From 5453629532027e52a0778522d1ba3b52e9585217 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sat, 29 Jun 2024 14:17:41 +0200 Subject: [PATCH] fix(#170): wait for the IOLoop to be stopped before attempting to close it. --- livereload/server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/livereload/server.py b/livereload/server.py index e6d8d8e..d26366b 100644 --- a/livereload/server.py +++ b/livereload/server.py @@ -347,8 +347,12 @@ def opener(): try: self.watcher._changes.append(('__livereload__', restart_delay)) LiveReloadHandler.start_tasks() - add_reload_hook(lambda: IOLoop.instance().close(all_fds=True)) + # When autoreload is triggered, initiate a shutdown of the IOLoop + add_reload_hook(lambda: IOLoop.instance().stop()) + # The call to start() does not return until the IOLoop is stopped. IOLoop.instance().start() + # Once the IOLoop is stopped, the IOLoop can be closed to free resources + IOLoop.current().close(all_fds=True) except KeyboardInterrupt: logger.info('Shutting down...')