From 7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 1 Oct 2023 20:29:57 +0200 Subject: Change event loop policy on windows Support more versions from curl_cffi --- g4f/Provider/helper.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'g4f/Provider/helper.py') diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py index 2c00a488..544c5a76 100644 --- a/g4f/Provider/helper.py +++ b/g4f/Provider/helper.py @@ -1,13 +1,20 @@ from __future__ import annotations -import asyncio +import asyncio, sys from asyncio import AbstractEventLoop import browser_cookie3 +# Change event loop policy on windows +if sys.platform == 'win32': + if isinstance( + asyncio.get_event_loop_policy(), asyncio.WindowsProactorEventLoopPolicy + ): + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + +# Local Cookie Storage _cookies: dict[str, dict[str, str]] = {} - # If event loop is already running, handle nested event loops # If "nest_asyncio" is installed, patch the event loop. def get_event_loop() -> AbstractEventLoop: -- cgit v1.2.3