Skip to content

Commit

Permalink
Stop useless tracking of running curl instances in AsyncSession
Browse files Browse the repository at this point in the history
  • Loading branch information
perklet committed Sep 22, 2023
1 parent 0fffcd8 commit 99cc8e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions curl_cffi/requests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def __init__(
self.loop = loop
self._acurl = async_curl
self.max_clients = max_clients
self.reset()
self.init_pool()
if sys.version_info >= (3, 8) and sys.platform.lower().startswith("win"):
if isinstance(
asyncio.get_event_loop_policy(), asyncio.WindowsProactorEventLoopPolicy
Expand All @@ -638,20 +638,18 @@ def acurl(self):
self._acurl = AsyncCurl(loop=self.loop)
return self._acurl

def reset(self):
def init_pool(self):
self.pool = asyncio.LifoQueue(self.max_clients)
while True:
try:
self.pool.put_nowait(None)
except asyncio.QueueFull:
break
self._running_curl = []

async def pop_curl(self):
curl = await self.pool.get()
if curl is None:
curl = Curl(debug=self.debug)
self._running_curl.append(curl)
return curl

def push_curl(self, curl):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "curl_cffi"
version = "0.5.9b5"
version = "0.5.9"
authors = [{ name = "Yifei Kong", email = "kong@yifei.me" }]
description = "libcurl ffi bindings for Python, with impersonation support"
license = { file = "LICENSE" }
Expand Down

0 comments on commit 99cc8e5

Please sign in to comment.