From 0a0993f9e09bab86bb3bb604bc2556c689740a76 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 28 Jun 2022 15:29:11 -0400 Subject: [PATCH] server: sleep 1ms after calling component close methods This allows any cancelled tasks to run through the eventloop before loop.stop() is called. Signed-off-by: Eric Callahan --- moonraker/moonraker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index 26164be..ba3cd1e 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -373,6 +373,8 @@ class Server: except Exception: logging.exception( f"Error executing 'close()' for component: {name}") + # Allow cancelled tasks a chance to run in the eventloop + await asyncio.sleep(.001) self.exit_reason = exit_reason self.event_loop.remove_signal_handler(signal.SIGTERM)