From d76da8a59ddcffd54e946e390a17a07da13997e9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-RTLN3BA\\$punk" Date: Thu, 30 Oct 2025 12:05:06 -0700 Subject: [PATCH] fix: podcast tasks for Windows compatibility - Added WindowsProactorEventLoopPolicy for better async subprocess support on Windows. - Ensured proper cleanup of the event loop after task execution. - Removed redundant asyncio import from the generate_chat_podcast_task function. --- .../app/tasks/celery_tasks/podcast_tasks.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/surfsense_backend/app/tasks/celery_tasks/podcast_tasks.py b/surfsense_backend/app/tasks/celery_tasks/podcast_tasks.py index e6ac91ca7..59a3bb2b1 100644 --- a/surfsense_backend/app/tasks/celery_tasks/podcast_tasks.py +++ b/surfsense_backend/app/tasks/celery_tasks/podcast_tasks.py @@ -1,6 +1,8 @@ """Celery tasks for podcast generation.""" +import asyncio import logging +import sys from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine from sqlalchemy.pool import NullPool @@ -11,6 +13,14 @@ from app.tasks.podcast_tasks import generate_chat_podcast logger = logging.getLogger(__name__) +if sys.platform.startswith("win"): + try: + asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) + except AttributeError: + logger.warning( + "WindowsProactorEventLoopPolicy is unavailable; async subprocess support may fail." + ) + def get_celery_session_maker(): """ @@ -39,8 +49,6 @@ def generate_chat_podcast_task( podcast_title: Title for the podcast user_id: ID of the user """ - import asyncio - loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) @@ -48,7 +56,9 @@ def generate_chat_podcast_task( loop.run_until_complete( _generate_chat_podcast(chat_id, search_space_id, podcast_title, user_id) ) + loop.run_until_complete(loop.shutdown_asyncgens()) finally: + asyncio.set_event_loop(None) loop.close()