Merge pull request #2240 from pipecat-ai/filipi/sig_term
Adding support for handle_sigterm
This commit is contained in:
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Added a new field `handle_sigterm` to `PipelineRunner`. It defaults to `False`.
|
||||||
|
This field handles SIGTERM signals. The `handle_sigint` field still defaults
|
||||||
|
to `True`, but now it handles only SIGINT signals.
|
||||||
|
|
||||||
- Added foundational example `14u-function-calling-ollama.py` for Ollama
|
- Added foundational example `14u-function-calling-ollama.py` for Ollama
|
||||||
function calling.
|
function calling.
|
||||||
|
|
||||||
|
|||||||
@@ -38,14 +38,16 @@ class PipelineRunner(BaseObject):
|
|||||||
handle_sigint: bool = True,
|
handle_sigint: bool = True,
|
||||||
force_gc: bool = False,
|
force_gc: bool = False,
|
||||||
loop: Optional[asyncio.AbstractEventLoop] = None,
|
loop: Optional[asyncio.AbstractEventLoop] = None,
|
||||||
|
handle_sigterm: bool = False,
|
||||||
):
|
):
|
||||||
"""Initialize the pipeline runner.
|
"""Initialize the pipeline runner.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: Optional name for the runner instance.
|
name: Optional name for the runner instance.
|
||||||
handle_sigint: Whether to automatically handle SIGINT/SIGTERM signals.
|
handle_sigint: Whether to automatically handle SIGINT signals.
|
||||||
force_gc: Whether to force garbage collection after task completion.
|
force_gc: Whether to force garbage collection after task completion.
|
||||||
loop: Event loop to use. If None, uses the current running loop.
|
loop: Event loop to use. If None, uses the current running loop.
|
||||||
|
handle_sigterm: Whether to automatically handle SIGTERM signals.
|
||||||
"""
|
"""
|
||||||
super().__init__(name=name)
|
super().__init__(name=name)
|
||||||
|
|
||||||
@@ -57,6 +59,9 @@ class PipelineRunner(BaseObject):
|
|||||||
if handle_sigint:
|
if handle_sigint:
|
||||||
self._setup_sigint()
|
self._setup_sigint()
|
||||||
|
|
||||||
|
if handle_sigterm:
|
||||||
|
self._setup_sigterm()
|
||||||
|
|
||||||
async def run(self, task: PipelineTask):
|
async def run(self, task: PipelineTask):
|
||||||
"""Run a pipeline task to completion.
|
"""Run a pipeline task to completion.
|
||||||
|
|
||||||
@@ -96,6 +101,10 @@ class PipelineRunner(BaseObject):
|
|||||||
"""Set up signal handlers for graceful shutdown."""
|
"""Set up signal handlers for graceful shutdown."""
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
loop.add_signal_handler(signal.SIGINT, lambda *args: self._sig_handler())
|
loop.add_signal_handler(signal.SIGINT, lambda *args: self._sig_handler())
|
||||||
|
|
||||||
|
def _setup_sigterm(self):
|
||||||
|
"""Set up signal handlers for graceful shutdown."""
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
loop.add_signal_handler(signal.SIGTERM, lambda *args: self._sig_handler())
|
loop.add_signal_handler(signal.SIGTERM, lambda *args: self._sig_handler())
|
||||||
|
|
||||||
def _sig_handler(self):
|
def _sig_handler(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user