close sessions
This commit is contained in:
parent
0c171e84c8
commit
d3df1c593a
10
stream.py
10
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 = []
|
||||
|
Loading…
Reference in New Issue
Block a user