Skip to content

Commit 1705854

Browse files
fix bug
1 parent bc29b1c commit 1705854

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

webcap/helpers.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import io
21
import re
3-
import sys
4-
import time
5-
import httpx
6-
import shutil
72
import asyncio
8-
import inspect
93
import logging
10-
import zipfile
4+
import traceback
115
from pathlib import Path
126
from contextlib import suppress
137
from urllib.parse import urlparse
@@ -32,18 +26,19 @@ def new_task():
3226
task = asyncio.create_task(fn(arg, **global_kwargs))
3327
tasks[task] = arg
3428

35-
for _ in range(threads): # Start initial batch of tasks
3629
for _ in range(threads):
3730
new_task()
3831

39-
while tasks: # While there are tasks pending
40-
# Wait for the first task to complete
4132
while tasks:
4233
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
4334
for task in done:
4435
arg = tasks.pop(task)
45-
result = task.result()
46-
yield arg, result
36+
try:
37+
result = task.result()
38+
yield arg, result
39+
except Exception as e:
40+
log.error(f"Error in task {arg}: {e}")
41+
log.debug(traceback.format_exc())
4742
new_task()
4843
except (KeyboardInterrupt, asyncio.CancelledError):
4944
for task in tasks:
@@ -76,7 +71,6 @@ def validate_urls(urls):
7671
for url in urls:
7772
parsed_url = urlparse(url)
7873
if (not parsed_url.netloc) or (parsed_url.scheme not in ["http", "https"]):
79-
if not parsed_url.netloc or parsed_url.scheme not in ["http", "https"]:
8074
log.warning(f"skipping invalid URL: {url}")
8175
continue
8276
yield url

0 commit comments

Comments
 (0)