Skip to content

Commit c5ce6e1

Browse files
Merge pull request #77 from blacklanternsecurity/dev
Fix timeout bug
2 parents 4aa98e6 + 1705854 commit c5ce6e1

2 files changed

Lines changed: 19 additions & 14 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: 19 additions & 12 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,16 +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
29+
for _ in range(threads):
3630
new_task()
3731

38-
while tasks: # While there are tasks pending
39-
# Wait for the first task to complete
32+
while tasks:
4033
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
4134
for task in done:
4235
arg = tasks.pop(task)
43-
result = task.result()
44-
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())
4542
new_task()
4643
except (KeyboardInterrupt, asyncio.CancelledError):
4744
for task in tasks:
@@ -224,6 +221,16 @@ def truncate_filename(file_path, max_length=255):
224221

225222

226223
def color_status_code(status_code):
224+
"""
225+
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.
226+
227+
Args:
228+
status_code (int or str): An HTTP status code represented as either an integer or string.
229+
230+
Returns:
231+
str: A colored string representation of the status code, indicating its severity level.
232+
233+
"""
227234
status_code = str(status_code)
228235
if status_code == "404":
229236
color = "orchid"

0 commit comments

Comments
 (0)