Skip to content

Commit

Permalink
Merge pull request #25 from daily-co/keyboard-interrupt
Browse files Browse the repository at this point in the history
Call client.leave on keyboard interrupt
  • Loading branch information
Moishe authored Feb 13, 2024
2 parents 08144fc + 4fecc10 commit 2516670
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/dailyai/services/base_transport_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down
12 changes: 10 additions & 2 deletions src/dailyai/services/daily_transport_service.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import inspect
import logging
import signal
import threading
import time
import types

from functools import partial
Expand All @@ -11,7 +11,7 @@
TranscriptionQueueFrame,
)

from threading import Thread, Event
from threading import Event

from daily import (
EventHandler,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2516670

Please sign in to comment.