Add loop argument to signal router finalize method to finalize without having a running loop

Closes #2829
This commit is contained in:
Eelke van den Bos 2023-09-27 01:09:55 -04:00 committed by GitHub
parent a5a9658896
commit 45b6e6d8c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -277,7 +277,7 @@ class SignalRouter(BaseRouter):
return cast(Signal, signal) 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 """Finalize the router and compile the routes
Args: Args:
@ -293,7 +293,7 @@ class SignalRouter(BaseRouter):
self.add(_blank, "sanic.__signal__.__init__") self.add(_blank, "sanic.__signal__.__init__")
try: try:
self.ctx.loop = asyncio.get_running_loop() self.ctx.loop = loop or asyncio.get_running_loop()
except RuntimeError: except RuntimeError:
raise RuntimeError("Cannot finalize signals outside of event loop") raise RuntimeError("Cannot finalize signals outside of event loop")