From 47f0437973c0c3777478924a3fd80f58ef798dc2 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 4 Feb 2022 18:14:46 -0500 Subject: [PATCH] eventloop: add a reset method Rather than instantiate a new version of the event loop wrapper we can simply reset the internal event loop. Signed-off-by: Eric Callahan --- moonraker/eventloop.py | 3 +++ moonraker/moonraker.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/moonraker/eventloop.py b/moonraker/eventloop.py index 972b8db..9d6642f 100644 --- a/moonraker/eventloop.py +++ b/moonraker/eventloop.py @@ -27,6 +27,9 @@ if TYPE_CHECKING: class EventLoop: TimeoutError = asyncio.TimeoutError def __init__(self) -> None: + self.reset() + + def reset(self) -> None: self.aioloop = asyncio.get_event_loop() self.add_signal_handler = self.aioloop.add_signal_handler self.remove_signal_handler = self.aioloop.remove_signal_handler diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index a41accd..e1ed629 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -952,7 +952,7 @@ def main() -> None: else: raise RuntimeError("Unable to create new open eventloop") asyncio.set_event_loop(new_loop) - event_loop = EventLoop() + event_loop.reset() event_loop.close() logging.info("Server Shutdown") ql.stop()