From c8d37a7227e23f7d21e3b9d0ae7a3c7bbd1fc159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 4 Jun 2024 15:08:11 -0700 Subject: [PATCH] pipeline(runner): add support for SIGTERM --- CHANGELOG.md | 3 +++ src/pipecat/pipeline/runner.py | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb6617ed..1c73a1832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `PipelineTask` now has a `has_finished()` method to indicate if the task has completed. If a task is never ran `has_finished()` will return False. +- `PipelineRunner` now supports SIGTERM. If received, the runner will be + canceled. + ### Fixed - Fixed an error closing local audio transports. diff --git a/src/pipecat/pipeline/runner.py b/src/pipecat/pipeline/runner.py index 47754d82f..df480648e 100644 --- a/src/pipecat/pipeline/runner.py +++ b/src/pipecat/pipeline/runner.py @@ -43,11 +43,15 @@ class PipelineRunner: loop = asyncio.get_running_loop() loop.add_signal_handler( signal.SIGINT, - lambda *args: asyncio.create_task(self._sigint_handler()) + lambda *args: asyncio.create_task(self._sig_handler()) + ) + loop.add_signal_handler( + signal.SIGTERM, + lambda *args: asyncio.create_task(self._sig_handler()) ) - async def _sigint_handler(self): - logger.warning(f"Ctrl-C detected. Canceling runner {self}") + async def _sig_handler(self): + logger.warning(f"Interruption detected. Canceling runner {self}") await self.cancel() def __str__(self):