返回提交历史
Modified
g4f/Provider/helper.py
+10
-4
XFEstudio/gpt4free
Remove deprecation in get_event_loop
84723102
代码差异
1 个文件
+10
-4
@@ -5,7 +5,7 @@ import os
5
5
import random
6
6
import secrets
7
7
import string
8
from asyncio import AbstractEventLoop
8
from asyncio import AbstractEventLoop, BaseEventLoop
9
9
from platformdirs import user_config_dir
10
10
from browser_cookie3 import (
11
11
chrome, chromium, opera, opera_gx,
@@ -27,13 +27,19 @@ def get_event_loop() -> AbstractEventLoop:
27
27
AbstractEventLoop: The current or new event loop.
28
28
"""
29
29
try:
30
loop = asyncio.get_running_loop()
30
loop = asyncio.get_event_loop()
31
if isinstance(loop, BaseEventLoop):
32
loop._check_closed()
33
except RuntimeError:
34
loop = asyncio.new_event_loop()
35
asyncio.set_event_loop(loop)
36
try:
37
asyncio.get_running_loop()
31
38
if not hasattr(loop.__class__, "_nest_patched"):
32
39
import nest_asyncio
33
40
nest_asyncio.apply(loop)
34
41
except RuntimeError:
35
loop = asyncio.new_event_loop()
36
asyncio.set_event_loop(loop)
42
pass
37
43
except ImportError:
38
44
raise RuntimeError(
39
45
'Use "create_async" instead of "create" function in a running event loop. Or install "nest_asyncio" package.'