task: allow queuing a CancelFrame to cancel the task

This commit is contained in:
Aleix Conchillo Flaqué
2025-01-28 15:51:22 -08:00
parent 3fe2124314
commit 0547a15695
2 changed files with 5 additions and 1 deletions

View File

@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a `PipelineTask` issue that was preventing processors to be cleaned up
after cancelling the task.
- Fixed an issue where queuing a `CancelFrame` to a pipeline task would not
cause the task to finish. However, using `PipelineTask.cancel()` is still the
recommended way to cancel a task.
### Other
- Updated all examples to use `task.cancel()` instead of pushing an `EndFrame`

View File

@@ -279,7 +279,7 @@ class PipelineTask(BaseTask):
await self._source.queue_frame(frame, FrameDirection.DOWNSTREAM)
if isinstance(frame, EndFrame):
await self._wait_for_endframe()
running = not isinstance(frame, (StopTaskFrame, EndFrame))
running = not isinstance(frame, (CancelFrame, EndFrame, StopTaskFrame))
should_cleanup = not isinstance(frame, StopTaskFrame)
self._push_queue.task_done()
# Cleanup only if we need to.