diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index 8156059..5fff93b 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -845,7 +845,18 @@ def main() -> None: # it is ok to use a blocking sleep here time.sleep(.5) logging.info("Attempting Server Restart...") - asyncio.set_event_loop(asyncio.new_event_loop()) + for _ in range(5): + # Sometimes the new loop does not properly instantiate. + # Give 5 attempts before raising an exception + new_loop = asyncio.new_event_loop() + if not new_loop.is_closed(): + break + logging.info("Failed to create open eventloop, " + "retyring in .5 seconds...") + time.sleep(.5) + else: + raise RuntimeError("Unable to create new open eventloop") + asyncio.set_event_loop(new_loop) event_loop = EventLoop() event_loop.close() logging.info("Server Shutdown")