PipelineTask: set finished_event InterruptionFrame is received

This commit is contained in:
Aleix Conchillo Flaqué
2025-10-10 20:27:24 -07:00
parent a1c07039ee
commit c33b81bb92
3 changed files with 13 additions and 4 deletions

View File

@@ -862,7 +862,7 @@ class InterruptionFrame(SystemFrame):
with other frames (so the order is not guaranteed).
Parameters:
wait_event: If not None, the event will be set when the frame
finished_event: If not None, the event will be set when the frame
reaches the end of the pipeline.
"""

View File

@@ -745,7 +745,7 @@ class PipelineTask(BasePipelineTask):
# pipeline. This is in case the push task is blocked waiting for a
# pipeline-ending frame to finish traversing the pipeline.
logger.debug(f"{self}: received interruption task frame {frame}")
await self._pipeline.queue_frame(InterruptionFrame())
await self._pipeline.queue_frame(InterruptionFrame(finished_event=frame.finished_event))
elif isinstance(frame, ErrorFrame):
await self._call_event_handler("on_pipeline_error", frame)
if frame.fatal:
@@ -786,6 +786,10 @@ class PipelineTask(BasePipelineTask):
self._pipeline_end_event.set()
elif isinstance(frame, HeartbeatFrame):
await self._heartbeat_queue.put(frame)
elif isinstance(frame, InterruptionFrame) and frame.finished_event:
# This should unblock any code waiting for the interruption to
# complete.
frame.finished_event.set()
async def _heartbeat_push_handler(self):
"""Push heartbeat frames at regular intervals."""