moonraker: create a new asyncio event loop on restart

This should guarantee that no dangliing callbacks are leftover on a soft restart.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-07-15 06:57:54 -04:00
parent 0d1431395e
commit 1fdfb5299e
1 changed files with 4 additions and 0 deletions

View File

@ -7,6 +7,7 @@
from __future__ import annotations
import argparse
from asyncio.events import new_event_loop
import sys
import importlib
import os
@ -765,10 +766,13 @@ def main() -> None:
break
if server.exit_reason == "terminate":
break
event_loop.close()
# Since we are running outside of the the server
# 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())
event_loop = EventLoop()
event_loop.close()
logging.info("Server Shutdown")
ql.stop()