fix(daemon): install signal handlers inside running event loop
_install_signal_handlers() was called before asyncio.run(), registering handlers on a throwaway loop that asyncio.get_event_loop() created — so SIGTERM would never reach the supervisor. Move the call into _run_daemon() and switch to asyncio.get_running_loop() so handlers are registered on the actual running loop. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -144,6 +144,9 @@ def _make_ipc_handler(supervisor: PluginSupervisor):
|
||||
async def _run_daemon(cfg, supervisor: PluginSupervisor) -> None:
|
||||
from pyra.daemon.ipc import IpcServer, get_socket_path, is_unix_socket
|
||||
|
||||
# Install signal handlers now that the event loop is running.
|
||||
_install_signal_handlers(supervisor)
|
||||
|
||||
if is_unix_socket():
|
||||
address = get_socket_path(cfg.daemon.socket_path)
|
||||
else:
|
||||
@@ -194,7 +197,6 @@ def run_foreground() -> None:
|
||||
_start_time = time.monotonic()
|
||||
|
||||
with pid_file:
|
||||
_install_signal_handlers(supervisor)
|
||||
_log.info("Pyra daemon starting (PID %d).", os.getpid())
|
||||
try:
|
||||
asyncio.run(_run_daemon(cfg, supervisor))
|
||||
@@ -266,7 +268,7 @@ def _install_signal_handlers(supervisor: PluginSupervisor) -> None:
|
||||
signal.signal(signal.SIGTERM, lambda *_: supervisor.request_shutdown())
|
||||
return
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.add_signal_handler(signal.SIGTERM, supervisor.request_shutdown)
|
||||
loop.add_signal_handler(signal.SIGHUP, supervisor.request_shutdown)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user