Skip to content

Commit bc29b1c

Browse files
fix timeout bug
1 parent 90474a2 commit bc29b1c

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

webcap/browser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ async def screenshot(self, url):
125125
return tab.webscreenshot
126126
except asyncio.TimeoutError:
127127
self.log.info(f"URL {url} load timed out after {self.timeout} seconds")
128-
raise
129128
except Exception as e:
130129
self.log.error(f"Error visiting {url}: {e}")
131-
raise
132130
finally:
133131
with suppress(Exception):
134132
await tab.close()

webcap/helpers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ def new_task():
3333
tasks[task] = arg
3434

3535
for _ in range(threads): # Start initial batch of tasks
36+
for _ in range(threads):
3637
new_task()
3738

3839
while tasks: # While there are tasks pending
3940
# Wait for the first task to complete
41+
while tasks:
4042
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
4143
for task in done:
4244
arg = tasks.pop(task)
@@ -74,6 +76,7 @@ def validate_urls(urls):
7476
for url in urls:
7577
parsed_url = urlparse(url)
7678
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"]:
7780
log.warning(f"skipping invalid URL: {url}")
7881
continue
7982
yield url
@@ -224,6 +227,16 @@ def truncate_filename(file_path, max_length=255):
224227

225228

226229
def color_status_code(status_code):
230+
"""
231+
This function takes an HTTP status code as input and returns it in bold with a specific color based on the first digit of the status code.
232+
233+
Args:
234+
status_code (int or str): An HTTP status code represented as either an integer or string.
235+
236+
Returns:
237+
str: A colored string representation of the status code, indicating its severity level.
238+
239+
"""
227240
status_code = str(status_code)
228241
if status_code == "404":
229242
color = "orchid"

0 commit comments

Comments
 (0)