summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-14 16:36:29 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-14 16:36:29 +0100
commitc3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea (patch)
treed7e5f2ad86beabd68fb08612b86b2a66242bf385 /g4f/Provider/helper.py
parentFix version not found (diff)
downloadgpt4free-c3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea.tar
gpt4free-c3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea.tar.gz
gpt4free-c3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea.tar.bz2
gpt4free-c3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea.tar.lz
gpt4free-c3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea.tar.xz
gpt4free-c3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea.tar.zst
gpt4free-c3d48ae4d0bb42ed8468cdcfb79690fc6d1bacea.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/helper.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py
index fce1ee6f..160074f7 100644
--- a/g4f/Provider/helper.py
+++ b/g4f/Provider/helper.py
@@ -5,7 +5,7 @@ import os
import random
import secrets
import string
-from asyncio import AbstractEventLoop, BaseEventLoop
+from asyncio import AbstractEventLoop
from platformdirs import user_config_dir
from browser_cookie3 import (
chrome, chromium, opera, opera_gx,
@@ -27,19 +27,13 @@ def get_event_loop() -> AbstractEventLoop:
AbstractEventLoop: The current or new event loop.
"""
try:
- loop = asyncio.get_event_loop()
- if isinstance(loop, BaseEventLoop):
- loop._check_closed()
- except RuntimeError:
- loop = asyncio.new_event_loop()
- asyncio.set_event_loop(loop)
- try:
- asyncio.get_running_loop()
+ loop = asyncio.get_running_loop()
if not hasattr(loop.__class__, "_nest_patched"):
import nest_asyncio
nest_asyncio.apply(loop)
except RuntimeError:
- pass
+ loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(loop)
except ImportError:
raise RuntimeError(
'Use "create_async" instead of "create" function in a running event loop. Or install "nest_asyncio" package.'