Compare commits
1 Commits
main
...
reloader-e
Author | SHA1 | Date | |
---|---|---|---|
|
f3035abfae |
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||||
from inspect import isawaitable
|
from inspect import isawaitable
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional
|
from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
|
|
||||||
|
@ -12,6 +11,7 @@ def trigger_events(
|
||||||
events: Optional[Iterable[Callable[..., Any]]],
|
events: Optional[Iterable[Callable[..., Any]]],
|
||||||
loop,
|
loop,
|
||||||
app: Optional[Sanic] = None,
|
app: Optional[Sanic] = None,
|
||||||
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Trigger event callbacks (functions or async)
|
Trigger event callbacks (functions or async)
|
||||||
|
@ -22,8 +22,12 @@ def trigger_events(
|
||||||
if events:
|
if events:
|
||||||
for event in events:
|
for event in events:
|
||||||
try:
|
try:
|
||||||
result = event() if not app else event(app)
|
result = event(**kwargs) if not app else event(app, **kwargs)
|
||||||
except TypeError:
|
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):
|
if isawaitable(result):
|
||||||
loop.run_until_complete(result)
|
loop.run_until_complete(result)
|
||||||
|
|
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from asyncio import new_event_loop
|
from asyncio import new_event_loop
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from multiprocessing.connection import Connection
|
from multiprocessing.connection import Connection
|
||||||
|
@ -64,7 +63,7 @@ class Reloader:
|
||||||
trigger_events(before_trigger, loop, app)
|
trigger_events(before_trigger, loop, app)
|
||||||
self.reload(",".join(changed) if changed else "unknown")
|
self.reload(",".join(changed) if changed else "unknown")
|
||||||
if after_trigger:
|
if after_trigger:
|
||||||
trigger_events(after_trigger, loop, app)
|
trigger_events(after_trigger, loop, app, changed=changed)
|
||||||
sleep(self.interval)
|
sleep(self.interval)
|
||||||
else:
|
else:
|
||||||
if reloader_stop:
|
if reloader_stop:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user