diff --git a/src/dailyai/services/base_transport_service.py b/src/dailyai/services/base_transport_service.py index b05e7e373..beaab2b20 100644 --- a/src/dailyai/services/base_transport_service.py +++ b/src/dailyai/services/base_transport_service.py @@ -76,6 +76,9 @@ async def run(self): except Exception as e: self._logger.error(f"Exception {e}") raise e + finally: + # Do anything that must be done to clean up + self._post_run() self._stop_threads.set() @@ -87,6 +90,9 @@ async def run(self): if self._speaker_enabled: self._receive_audio_thread.join() + def _post_run(self): + pass + def stop(self): self._stop_threads.set() diff --git a/src/dailyai/services/daily_transport_service.py b/src/dailyai/services/daily_transport_service.py index 2f07e6d63..f29633d87 100644 --- a/src/dailyai/services/daily_transport_service.py +++ b/src/dailyai/services/daily_transport_service.py @@ -1,8 +1,8 @@ import asyncio import inspect import logging +import signal import threading -import time import types from functools import partial @@ -11,7 +11,7 @@ TranscriptionQueueFrame, ) -from threading import Thread, Event +from threading import Event from daily import ( EventHandler, @@ -194,6 +194,14 @@ def _prerun(self): if self._token and self._start_transcription: self.client.start_transcription(self.transcription_settings) + signal.signal(signal.SIGINT, self.process_interrupt_handler) + + def process_interrupt_handler(self, signum, frame): + self._post_run() + + def _post_run(self): + self.client.leave() + def on_first_other_participant_joined(self): pass