cancel tasks in loop

This commit is contained in:
Roy Olav Purser 2021-05-14 21:55:56 +02:00
parent 55de3febd9
commit 0c171e84c8
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -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: