close sessions

This commit is contained in:
Roy Olav Purser 2021-05-14 23:09:16 +02:00
parent 0c171e84c8
commit d3df1c593a
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -89,12 +89,10 @@ class AsyncSessionData():
self.current_proxies = current_proxies
self.current_proxy = current_proxy
class AsyncSession():
def __init__(self, session, resp, current_proxies, current_proxy):
self.session = session
def __init__(self, resp, current_proxies, current_proxy):
self.sdata = AsyncSessionData(resp, current_proxies, current_proxy)
async def task(self):
resp = await self.sdata.resp
await self.session.close()
return AsyncSessionData(resp, self.sdata.current_proxies, self.sdata.current_proxy)
proxies = {}
@ -150,12 +148,14 @@ class UpstreamHandler():
proxy_iter = proxy_list_orig.copy()
if isinstance(proxy_list, list):
futures = []
sessions = []
for i in proxy_iter:
current_list = proxy_list.copy()
current = proxy_list.pop()
proxy_list = [current] + proxy_list
session = current.session()
future = AsyncSession(session, session.head(src), current_list, current)
sessions.append(session)
future = AsyncSession(session.head(src), current_list, current)
task = asyncio.create_task(future.task())
futures.append(task)
done = False
@ -180,6 +180,8 @@ class UpstreamHandler():
for future in futures:
if not future.done():
future.cancel()
for session in sessions:
await session.close()
async def meta(self):
data = []