From 45b6e6d8c422ffc46431ae22548c7908efebb35e Mon Sep 17 00:00:00 2001 From: Eelke van den Bos Date: Wed, 27 Sep 2023 01:09:55 -0400 Subject: [PATCH] Add `loop` argument to signal router `finalize` method to finalize without having a running loop Closes #2829 --- sanic/signals.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/signals.py b/sanic/signals.py index fe252c12..1ca22c32 100644 --- a/sanic/signals.py +++ b/sanic/signals.py @@ -277,7 +277,7 @@ class SignalRouter(BaseRouter): return cast(Signal, signal) - def finalize(self, do_compile: bool = True, do_optimize: bool = False): + def finalize(self, do_compile: bool = True, do_optimize: bool = False, loop: asyncio.AbstractEventLoop = None): """Finalize the router and compile the routes Args: @@ -293,7 +293,7 @@ class SignalRouter(BaseRouter): self.add(_blank, "sanic.__signal__.__init__") try: - self.ctx.loop = asyncio.get_running_loop() + self.ctx.loop = loop or asyncio.get_running_loop() except RuntimeError: raise RuntimeError("Cannot finalize signals outside of event loop")