From 3bf4e1defb88373c5020b7ac10991ae69f77b5c4 Mon Sep 17 00:00:00 2001 From: Willem Jiang Date: Sat, 6 Dec 2025 22:10:13 +0800 Subject: [PATCH] fix: setup WindowsSelectorEventLoopPolicy in the first place #741 (#742) * fix: setup WindowsSelectorEventLoopPolicy in the first place #741 * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Willem Jiang <143703838+willem-bd@users.noreply.github.com> --- src/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/__init__.py b/src/__init__.py index 58bc29b..b912cbd 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,2 +1,11 @@ # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates # SPDX-License-Identifier: MIT +import asyncio +import os + + +# Configure Windows event loop policy for PostgreSQL compatibility +# On Windows, psycopg requires a selector-based event loop, not the default ProactorEventLoop +# This must be set at the earliest possible point before any event loop is created +if os.name == "nt": + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) \ No newline at end of file