Skip to content

Commit

Permalink
AsyncSession: change acurl to a lazy property, so that the instance c…
Browse files Browse the repository at this point in the history
…an be created out of async world
  • Loading branch information
perklet committed Sep 4, 2023
1 parent cf66d53 commit 9a8e5da
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions curl_cffi/requests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ def __init__(
```
"""
super().__init__(**kwargs)
self.loop = loop if loop is not None else asyncio.get_running_loop()
self.acurl = async_curl if async_curl is not None else AsyncCurl(loop=self.loop)
self.loop = loop
self._acurl = async_curl
self.max_clients = max_clients
self.reset()
if sys.version_info >= (3, 8) and sys.platform.lower().startswith("win"):
Expand All @@ -616,6 +616,14 @@ def __init__(
):
warnings.warn(WINDOWS_WARN)

@property
def acurl(self):
if self.loop is None:
self.loop = asyncio.get_running_loop()
if self._acurl is None:
self._acurl = AsyncCurl(loop=self.loop)
return self._acurl

def reset(self):
self.pool = asyncio.LifoQueue(self.max_clients)
while True:
Expand Down

0 comments on commit 9a8e5da

Please sign in to comment.