Merge pull request #2369 from pipecat-ai/aleix/pipeline-task-cancellation-fix
PipelineTask: always try to cancel things
This commit is contained in:
@@ -459,20 +459,10 @@ class PipelineTask(BasePipelineTask):
|
|||||||
# awaiting a task.
|
# awaiting a task.
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
# We only cancel things cleanly if we know we are the ones
|
await self._cancel_tasks()
|
||||||
# cancelling. It's possibe that we get an asyncio.CancelledError
|
await self._cleanup(cleanup_pipeline)
|
||||||
# from the outside, in which case it is very likely other tasks have
|
if self._check_dangling_tasks:
|
||||||
# been already cancelled (e.g. when python is shutting down) so we
|
self._print_dangling_tasks()
|
||||||
# can't assume things are being cancelled nicely.
|
|
||||||
if self._cancelled:
|
|
||||||
await self._cancel_tasks()
|
|
||||||
await self._cleanup(cleanup_pipeline)
|
|
||||||
if self._check_dangling_tasks:
|
|
||||||
self._print_dangling_tasks()
|
|
||||||
else:
|
|
||||||
logger.warning(
|
|
||||||
f"Pipeline task {self} is not being cancelled properly (use cancel() method)"
|
|
||||||
)
|
|
||||||
self._finished = True
|
self._finished = True
|
||||||
|
|
||||||
async def queue_frame(self, frame: Frame):
|
async def queue_frame(self, frame: Frame):
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ def _setup_daily_routes(app: FastAPI):
|
|||||||
|
|
||||||
# Start the bot in the background with empty body for GET requests
|
# Start the bot in the background with empty body for GET requests
|
||||||
bot_module = _get_bot_module()
|
bot_module = _get_bot_module()
|
||||||
runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
runner_args = DailyRunnerArguments(room_url=room_url, token=token)
|
||||||
runner_args.handle_sigint = False
|
runner_args.handle_sigint = False
|
||||||
asyncio.create_task(bot_module.bot(runner_args))
|
asyncio.create_task(bot_module.bot(runner_args))
|
||||||
return RedirectResponse(room_url)
|
return RedirectResponse(room_url)
|
||||||
@@ -395,7 +395,7 @@ async def _run_daily_direct():
|
|||||||
room_url, token = await configure(session)
|
room_url, token = await configure(session)
|
||||||
|
|
||||||
# Direct connections have no request body, so use empty dict
|
# Direct connections have no request body, so use empty dict
|
||||||
runner_args = DailyRunnerArguments(room_url=room_url, token=token, body={})
|
runner_args = DailyRunnerArguments(room_url=room_url, token=token)
|
||||||
|
|
||||||
# Get the bot module and run it directly
|
# Get the bot module and run it directly
|
||||||
bot_module = _get_bot_module()
|
bot_module = _get_bot_module()
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ class DailyRunnerArguments(RunnerArguments):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
room_url: str
|
room_url: str
|
||||||
token: Optional[str]
|
token: Optional[str] = None
|
||||||
body: Any
|
body: Optional[Any] = {}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user