Merge pull request #25 from daily-co/keyboard-interrupt

Call client.leave on keyboard interrupt
This commit is contained in:
Moishe Lettvin
2024-02-13 14:18:42 -05:00
committed by GitHub
2 changed files with 16 additions and 2 deletions

View File

@@ -76,6 +76,9 @@ class BaseTransportService():
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 @@ class BaseTransportService():
if self._speaker_enabled:
self._receive_audio_thread.join()
def _post_run(self):
pass
def stop(self):
self._stop_threads.set()

View File

@@ -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 @@ from dailyai.queue_frame import (
TranscriptionQueueFrame,
)
from threading import Thread, Event
from threading import Event
from daily import (
EventHandler,
@@ -194,6 +194,14 @@ class DailyTransportService(BaseTransportService, EventHandler):
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