diff --git a/stream_transcriber/streams.py b/stream_transcriber/streams.py index cf45ce9..d21e7d6 100644 --- a/stream_transcriber/streams.py +++ b/stream_transcriber/streams.py @@ -241,29 +241,29 @@ async def load_stream(stream_name: str): "Starting transcription", extra={"stream": stream_name}, ) - asr_task = asyncio.create_task(sm_client.run(runtime_stream, conf, settings)) - send_audio_task = asyncio.create_task(send_audio(broadcast_stream, stream_name)) - log_task = asyncio.create_task(log_ffmpeg(process)) + asr_task = asyncio.create_task( + sm_client.run(runtime_stream, conf, settings), name="asr_task" + ) + send_audio_task = asyncio.create_task( + send_audio(broadcast_stream, stream_name), name="send_audio_task" + ) + log_task = asyncio.create_task(log_ffmpeg(process), name="log_task") - done, pending = await asyncio.wait( + done, _ = await asyncio.wait( [log_task, send_audio_task, asr_task, stream_clone_task], return_when=asyncio.FIRST_EXCEPTION, ) + for done_routine in done: if done_routine.exception() is not None: + exception_name = type(done_routine.exception()).__name__ LOGGER.error( - "Exception in return %s", + "Exception for done routine: %s. Exception (%s): %s", + done_routine.get_name(), + exception_name, done_routine.exception(), extra={"stream": stream_name}, ) - for pending_routine in pending: - pending_routine.cancel() - if pending_routine.exception() is not None: - LOGGER.error( - "Exception in return %s", - pending_routine.exception(), - extra={"stream": stream_name}, - ) except asyncio.CancelledError: LOGGER.warning("Task Cancelled", extra={"stream": stream_name})