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) futures.append(task)
done = False done = False
for future in asyncio.as_completed(futures): for future in asyncio.as_completed(futures):
if done: try:
future.cancel() result = await future
resp = result.resp
except Exception as e:
logger.info(e)
else: else:
try: done = True
result = await future new_url = str(resp.url)
resp = result.resp if new_url.lower().startswith("https://consent.youtube.com"):
except Exception as e: self.upstream = src
logger.info(e) self.upstream_safe = urllib.parse.quote(src)
else: else:
done = True self.upstream = new_url
new_url = str(resp.url) self.upstream_safe = urllib.parse.quote(new_url)
if new_url.lower().startswith("https://consent.youtube.com"): self.proxy = result.current_proxy
self.upstream = src proxies[self.provider] = result.current_proxies
self.upstream_safe = urllib.parse.quote(src) break
else: for future in futures:
self.upstream = new_url if not future.done():
self.upstream_safe = urllib.parse.quote(new_url) future.cancel()
self.proxy = result.current_proxy
proxies[self.provider] = result.current_proxies
async def meta(self): async def meta(self):
data = [] data = []
try: try: