From 0a3fe0b7df7b2779ae795c8590d2a707d6672345 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 13 Apr 2024 18:02:47 +0200 Subject: Update event loop on windows only for old curl_cffi --- g4f/providers/base_provider.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'g4f/providers/base_provider.py') diff --git a/g4f/providers/base_provider.py b/g4f/providers/base_provider.py index 86789ec2..cb60d78f 100644 --- a/g4f/providers/base_provider.py +++ b/g4f/providers/base_provider.py @@ -19,8 +19,13 @@ else: # Set Windows event loop policy for better compatibility with asyncio and curl_cffi if sys.platform == 'win32': - if isinstance(asyncio.get_event_loop_policy(), asyncio.WindowsProactorEventLoopPolicy): - asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + try: + from curl_cffi import aio + if not hasattr(aio, "_get_selector"): + if isinstance(asyncio.get_event_loop_policy(), asyncio.WindowsProactorEventLoopPolicy): + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + except ImportError: + pass def get_running_loop(check_nested: bool) -> Union[AbstractEventLoop, None]: try: -- cgit v1.2.3