Spaces:
Running
Running
fixing shutdown (#156)
Browse files
src/reachy_mini_conversation_app/console.py
CHANGED
|
@@ -406,11 +406,25 @@ class LocalStream:
|
|
| 406 |
"""Stop the stream and underlying media pipelines.
|
| 407 |
|
| 408 |
This method:
|
|
|
|
| 409 |
- Sets the stop event to signal async loops to terminate
|
| 410 |
- Cancels all pending async tasks (openai-handler, record-loop, play-loop)
|
| 411 |
-
- Stops audio recording and playback
|
| 412 |
"""
|
| 413 |
logger.info("Stopping LocalStream...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
self._stop_event.set()
|
| 415 |
|
| 416 |
# Cancel all running tasks
|
|
@@ -418,9 +432,6 @@ class LocalStream:
|
|
| 418 |
if not task.done():
|
| 419 |
task.cancel()
|
| 420 |
|
| 421 |
-
self._robot.media.stop_recording()
|
| 422 |
-
self._robot.media.stop_playing()
|
| 423 |
-
|
| 424 |
def clear_audio_queue(self) -> None:
|
| 425 |
"""Flush the player's appsrc to drop any queued audio immediately."""
|
| 426 |
logger.info("User intervention: flushing player queue")
|
|
|
|
| 406 |
"""Stop the stream and underlying media pipelines.
|
| 407 |
|
| 408 |
This method:
|
| 409 |
+
- Stops audio recording and playback first
|
| 410 |
- Sets the stop event to signal async loops to terminate
|
| 411 |
- Cancels all pending async tasks (openai-handler, record-loop, play-loop)
|
|
|
|
| 412 |
"""
|
| 413 |
logger.info("Stopping LocalStream...")
|
| 414 |
+
|
| 415 |
+
# Stop media pipelines FIRST before cancelling async tasks
|
| 416 |
+
# This ensures clean shutdown before PortAudio cleanup
|
| 417 |
+
try:
|
| 418 |
+
self._robot.media.stop_recording()
|
| 419 |
+
except Exception as e:
|
| 420 |
+
logger.debug(f"Error stopping recording (may already be stopped): {e}")
|
| 421 |
+
|
| 422 |
+
try:
|
| 423 |
+
self._robot.media.stop_playing()
|
| 424 |
+
except Exception as e:
|
| 425 |
+
logger.debug(f"Error stopping playback (may already be stopped): {e}")
|
| 426 |
+
|
| 427 |
+
# Now signal async loops to stop
|
| 428 |
self._stop_event.set()
|
| 429 |
|
| 430 |
# Cancel all running tasks
|
|
|
|
| 432 |
if not task.done():
|
| 433 |
task.cancel()
|
| 434 |
|
|
|
|
|
|
|
|
|
|
| 435 |
def clear_audio_queue(self) -> None:
|
| 436 |
"""Flush the player's appsrc to drop any queued audio immediately."""
|
| 437 |
logger.info("User intervention: flushing player queue")
|
src/reachy_mini_conversation_app/main.py
CHANGED
|
@@ -190,6 +190,12 @@ def run(
|
|
| 190 |
if vision_manager:
|
| 191 |
vision_manager.stop()
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
# prevent connection to keep alive some threads
|
| 194 |
robot.client.disconnect()
|
| 195 |
time.sleep(1)
|
|
|
|
| 190 |
if vision_manager:
|
| 191 |
vision_manager.stop()
|
| 192 |
|
| 193 |
+
# Ensure media is explicitly closed before disconnecting
|
| 194 |
+
try:
|
| 195 |
+
robot.media.close()
|
| 196 |
+
except Exception as e:
|
| 197 |
+
logger.debug(f"Error closing media during shutdown: {e}")
|
| 198 |
+
|
| 199 |
# prevent connection to keep alive some threads
|
| 200 |
robot.client.disconnect()
|
| 201 |
time.sleep(1)
|