Skip to content

Commit

Permalink
attempt to fix proxyfree fail
Browse files Browse the repository at this point in the history
  • Loading branch information
glyh committed Sep 28, 2024
1 parent e2a43c7 commit 5ed7f36
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions javsp/network/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
import logging
import time
from tqdm.asyncio import tqdm
from typing import Any, Coroutine, NamedTuple
Expand All @@ -14,6 +15,8 @@

import asyncio

logger = logging.getLogger(__name__)

class DownloadInfo(NamedTuple):
size: ByteSize
elapsed: timedelta
Expand Down Expand Up @@ -63,16 +66,16 @@ async def test_connect(url_str: str, timeout: Duration) -> bool:
await client.get(
url_str,
timeout=timeout.total_seconds(),
follow_redirects=True,
)
return response.status_code == 200
except:
except Exception as e:
logger.debug(f"Not connectable: {url_str}\n" + repr(e))
return False

async def choose_one_connectable(urls: list[str]) -> str | None:
co_connectables: list[Coroutine[Any, Any, bool]] = []
for url in urls:
co_connectables.append(test_connect(url, Duration(seconds=5)))
co_connectables.append(test_connect(url, Duration(seconds=3)))

connectables = await asyncio.gather(*co_connectables)
for i, connectable in enumerate(connectables):
Expand Down

0 comments on commit 5ed7f36

Please sign in to comment.