formatting
This commit is contained in:
@@ -11,8 +11,6 @@ from typing import Any, Callable
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class AppDaemonRunContext:
|
||||
_stack: ExitStack = field(default_factory=ExitStack)
|
||||
@@ -28,7 +26,8 @@ class AppDaemonRunContext:
|
||||
|
||||
signals = (signal.SIGHUP, signal.SIGTERM, signal.SIGINT)
|
||||
for s in signals:
|
||||
self.loop.add_signal_handler(s, lambda s=s: self.loop.create_task(self.shutdown(s)))
|
||||
self.loop.add_signal_handler(
|
||||
s, lambda s=s: self.loop.create_task(self.shutdown(s)))
|
||||
|
||||
self.executor = self._stack.enter_context(self.thread_context())
|
||||
logger.debug("Started thread pool")
|
||||
@@ -46,7 +45,7 @@ class AppDaemonRunContext:
|
||||
|
||||
async def shutdown(self, signal=signal.SIGTERM):
|
||||
"""Cleanup tasks tied to the service's shutdown.
|
||||
|
||||
|
||||
https://www.roguelynn.com/words/asyncio-graceful-shutdowns/
|
||||
"""
|
||||
logger.info(f"Received exit signal {signal.name}...")
|
||||
@@ -60,7 +59,8 @@ class AppDaemonRunContext:
|
||||
asyncio.wait_for(t, timeout=self.shutdown_grace_period)
|
||||
for t in tasks
|
||||
)
|
||||
logger.debug(f'Allowing graceful shutdown from stop event for {self.shutdown_grace_period}s')
|
||||
logger.debug(f'Allowing graceful shutdown from stop event for {
|
||||
self.shutdown_grace_period}s')
|
||||
await asyncio.gather(*graceful, return_exceptions=True)
|
||||
|
||||
for task in tasks:
|
||||
|
||||
Reference in New Issue
Block a user