|
2 | 2 |
|
3 | 3 | # ruff: noqa: T100 |
4 | 4 | import asyncio |
| 5 | +from collections.abc import Callable |
5 | 6 | from importlib import import_module |
6 | 7 | import logging |
7 | 8 | import os |
@@ -289,26 +290,22 @@ def check_environment() -> None: |
289 | 290 | _LOGGER.critical("Can't find Docker socket!") |
290 | 291 |
|
291 | 292 |
|
292 | | -def register_signal_handlers(loop: asyncio.AbstractEventLoop, coresys: CoreSys) -> None: |
| 293 | +def register_signal_handlers( |
| 294 | + loop: asyncio.AbstractEventLoop, shutdown_handler: Callable[[], None] |
| 295 | +) -> None: |
293 | 296 | """Register SIGTERM, SIGHUP and SIGKILL to stop the Supervisor.""" |
294 | 297 | try: |
295 | | - loop.add_signal_handler( |
296 | | - signal.SIGTERM, lambda: loop.create_task(coresys.core.stop()) |
297 | | - ) |
| 298 | + loop.add_signal_handler(signal.SIGTERM, shutdown_handler) |
298 | 299 | except (ValueError, RuntimeError): |
299 | 300 | _LOGGER.warning("Could not bind to SIGTERM") |
300 | 301 |
|
301 | 302 | try: |
302 | | - loop.add_signal_handler( |
303 | | - signal.SIGHUP, lambda: loop.create_task(coresys.core.stop()) |
304 | | - ) |
| 303 | + loop.add_signal_handler(signal.SIGHUP, shutdown_handler) |
305 | 304 | except (ValueError, RuntimeError): |
306 | 305 | _LOGGER.warning("Could not bind to SIGHUP") |
307 | 306 |
|
308 | 307 | try: |
309 | | - loop.add_signal_handler( |
310 | | - signal.SIGINT, lambda: loop.create_task(coresys.core.stop()) |
311 | | - ) |
| 308 | + loop.add_signal_handler(signal.SIGINT, shutdown_handler) |
312 | 309 | except (ValueError, RuntimeError): |
313 | 310 | _LOGGER.warning("Could not bind to SIGINT") |
314 | 311 |
|
|
0 commit comments