From d3df1c593a3c2503fbd832edeb9df85f5290485d Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 14 May 2021 23:09:16 +0200 Subject: [PATCH] close sessions --- stream.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stream.py b/stream.py index 7fded1e..337802c 100755 --- a/stream.py +++ b/stream.py @@ -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 = []