diff --git a/sanic/server/events.py b/sanic/server/events.py index ae93c78e..deb94b16 100644 --- a/sanic/server/events.py +++ b/sanic/server/events.py @@ -3,7 +3,6 @@ from __future__ import annotations from inspect import isawaitable from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional - if TYPE_CHECKING: from sanic import Sanic @@ -12,6 +11,7 @@ def trigger_events( events: Optional[Iterable[Callable[..., Any]]], loop, app: Optional[Sanic] = None, + **kwargs, ): """ Trigger event callbacks (functions or async) @@ -22,8 +22,12 @@ def trigger_events( if events: for event in events: try: - result = event() if not app else event(app) + result = event(**kwargs) if not app else event(app, **kwargs) except TypeError: - result = event(loop) if not app else event(app, loop) + result = ( + event(loop, **kwargs) + if not app + else event(app, loop, **kwargs) + ) if isawaitable(result): loop.run_until_complete(result) diff --git a/sanic/worker/reloader.py b/sanic/worker/reloader.py index b490c5b3..07946992 100644 --- a/sanic/worker/reloader.py +++ b/sanic/worker/reloader.py @@ -2,7 +2,6 @@ from __future__ import annotations import os import sys - from asyncio import new_event_loop from itertools import chain from multiprocessing.connection import Connection @@ -64,7 +63,7 @@ class Reloader: trigger_events(before_trigger, loop, app) self.reload(",".join(changed) if changed else "unknown") if after_trigger: - trigger_events(after_trigger, loop, app) + trigger_events(after_trigger, loop, app, changed=changed) sleep(self.interval) else: if reloader_stop: