From f7f0c44c3241fbeb1d99b5ba2d82510044c42f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 24 Oct 2024 10:35:37 -0700 Subject: [PATCH] transports(daily): don't block event handlers --- src/pipecat/transports/services/daily.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pipecat/transports/services/daily.py b/src/pipecat/transports/services/daily.py index da232c224..05cb96b0d 100644 --- a/src/pipecat/transports/services/daily.py +++ b/src/pipecat/transports/services/daily.py @@ -584,8 +584,15 @@ class DailyTransportClient(EventHandler): ) def _call_async_callback(self, callback, *args): - future = asyncio.run_coroutine_threadsafe(callback(*args), self._loop) - future.result() + # Don't wait on the coroutine, otherwise if we call a `CallClient` + # function and wait for its completion this will currently result in a + # deadlock. This is because `_call_async_callback` is used inside + # `CallClient` event handlers which are holding the GIL in + # `daily-python`. So if the `callback` passed here makes a `CallClient` + # call and waits for it to finish using completions (and a future) we + # will deadlock because completions use event handlers (which are + # holding the GIL). + asyncio.run_coroutine_threadsafe(callback(*args), self._loop) class DailyInputTransport(BaseInputTransport):