cancel tasks in loop
This commit is contained in:
parent
55de3febd9
commit
0c171e84c8
36
stream.py
36
stream.py
@ -160,25 +160,27 @@ class UpstreamHandler():
|
||||
futures.append(task)
|
||||
done = False
|
||||
for future in asyncio.as_completed(futures):
|
||||
if done:
|
||||
future.cancel()
|
||||
try:
|
||||
result = await future
|
||||
resp = result.resp
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
else:
|
||||
try:
|
||||
result = await future
|
||||
resp = result.resp
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
done = True
|
||||
new_url = str(resp.url)
|
||||
if new_url.lower().startswith("https://consent.youtube.com"):
|
||||
self.upstream = src
|
||||
self.upstream_safe = urllib.parse.quote(src)
|
||||
else:
|
||||
done = True
|
||||
new_url = str(resp.url)
|
||||
if new_url.lower().startswith("https://consent.youtube.com"):
|
||||
self.upstream = src
|
||||
self.upstream_safe = urllib.parse.quote(src)
|
||||
else:
|
||||
self.upstream = new_url
|
||||
self.upstream_safe = urllib.parse.quote(new_url)
|
||||
self.proxy = result.current_proxy
|
||||
proxies[self.provider] = result.current_proxies
|
||||
self.upstream = new_url
|
||||
self.upstream_safe = urllib.parse.quote(new_url)
|
||||
self.proxy = result.current_proxy
|
||||
proxies[self.provider] = result.current_proxies
|
||||
break
|
||||
for future in futures:
|
||||
if not future.done():
|
||||
future.cancel()
|
||||
|
||||
async def meta(self):
|
||||
data = []
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user