lacuscore 1.9.3__py3-none-any.whl → 1.9.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lacuscore/lacuscore.py +20 -4
- {lacuscore-1.9.3.dist-info → lacuscore-1.9.4.dist-info}/METADATA +3 -3
- {lacuscore-1.9.3.dist-info → lacuscore-1.9.4.dist-info}/RECORD +5 -5
- {lacuscore-1.9.3.dist-info → lacuscore-1.9.4.dist-info}/LICENSE +0 -0
- {lacuscore-1.9.3.dist-info → lacuscore-1.9.4.dist-info}/WHEEL +0 -0
lacuscore/lacuscore.py
CHANGED
@@ -43,9 +43,19 @@ from .helpers import (
|
|
43
43
|
|
44
44
|
if sys.version_info < (3, 11):
|
45
45
|
from async_timeout import timeout
|
46
|
+
|
47
|
+
def timeout_expired(timeout_cm, logger, error_message: str) -> None: # type: ignore[no-untyped-def]
|
48
|
+
if timeout_cm.expired:
|
49
|
+
logger.warning(f'Timeout expired: {error_message}')
|
50
|
+
|
46
51
|
else:
|
47
52
|
from asyncio import timeout
|
48
53
|
|
54
|
+
def timeout_expired(timeout_cm, logger, error_message: str) -> None: # type: ignore[no-untyped-def]
|
55
|
+
if timeout_cm.expired():
|
56
|
+
logger.warning(f'Timeout expired: {error_message}')
|
57
|
+
|
58
|
+
|
49
59
|
BROWSER = Literal['chromium', 'firefox', 'webkit']
|
50
60
|
|
51
61
|
|
@@ -523,8 +533,6 @@ class LacusCore():
|
|
523
533
|
browser_engine = 'webkit'
|
524
534
|
try:
|
525
535
|
logger.debug(f'Capturing {url}')
|
526
|
-
# NOTE: starting with python 3.11, we can use asyncio.timeout
|
527
|
-
# async with asyncio.timeout(self.max_capture_time):
|
528
536
|
general_timeout = to_capture.get('general_timeout_in_sec')
|
529
537
|
stats_pipeline.sadd(f'stats:{today}:captures', url)
|
530
538
|
async with Capture(
|
@@ -545,12 +553,19 @@ class LacusCore():
|
|
545
553
|
capture.locale = to_capture.get('locale') # type: ignore[assignment]
|
546
554
|
capture.color_scheme = to_capture.get('color_scheme') # type: ignore[assignment]
|
547
555
|
try:
|
548
|
-
|
556
|
+
# make sure the initialization doesn't take too long
|
557
|
+
if general_timeout is None:
|
558
|
+
general_timeout = 5
|
559
|
+
init_timeout = max(general_timeout / 2, 5)
|
560
|
+
async with timeout(init_timeout) as initialize_timeout:
|
549
561
|
await capture.initialize_context()
|
562
|
+
|
550
563
|
except (TimeoutError, asyncio.exceptions.TimeoutError):
|
564
|
+
timeout_expired(initialize_timeout, logger, 'Initializing took too long.')
|
551
565
|
logger.warning(f'Initializing the context for {url} took longer than the allowed general timeout ({general_timeout}s)')
|
552
566
|
raise RetryCapture(f'Initializing the context for {url} took longer than the allowed general timeout ({general_timeout}s)')
|
553
|
-
|
567
|
+
|
568
|
+
async with timeout(self.max_capture_time) as capture_timeout:
|
554
569
|
playwright_result = await capture.capture_page(
|
555
570
|
url, referer=to_capture.get('referer'),
|
556
571
|
depth=to_capture.get('depth', 0),
|
@@ -576,6 +591,7 @@ class LacusCore():
|
|
576
591
|
# We can give it another short.
|
577
592
|
raise RetryCapture(f'The capture of {url} has been cancelled.')
|
578
593
|
except (TimeoutError, asyncio.exceptions.TimeoutError):
|
594
|
+
timeout_expired(capture_timeout, logger, 'Capture took too long.')
|
579
595
|
logger.warning(f'The capture of {url} took longer than the allowed max capture time ({self.max_capture_time}s)')
|
580
596
|
result = {'error': f'The capture of {url} took longer than the allowed max capture time ({self.max_capture_time}s)'}
|
581
597
|
raise CaptureError(f'The capture of {url} took longer than the allowed max capture time ({self.max_capture_time}s)')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: lacuscore
|
3
|
-
Version: 1.9.
|
3
|
+
Version: 1.9.4
|
4
4
|
Summary: Core of Lacus, usable as a module
|
5
5
|
Home-page: https://github.com/ail-project/LacusCore
|
6
6
|
License: BSD-3-Clause
|
@@ -28,9 +28,9 @@ Requires-Dist: Sphinx (>=7.2,<8.0) ; (python_version >= "3.9") and (extra == "do
|
|
28
28
|
Requires-Dist: async-timeout (>=4.0.3,<5.0.0) ; python_version < "3.11"
|
29
29
|
Requires-Dist: defang (>=0.5.3,<0.6.0)
|
30
30
|
Requires-Dist: dnspython (>=2.6.1,<3.0.0)
|
31
|
-
Requires-Dist: playwrightcapture[recaptcha] (>=1.24.
|
31
|
+
Requires-Dist: playwrightcapture[recaptcha] (>=1.24.10,<2.0.0)
|
32
32
|
Requires-Dist: redis[hiredis] (>=5.0.4,<6.0.0)
|
33
|
-
Requires-Dist: requests (>=2.
|
33
|
+
Requires-Dist: requests (>=2.32.1,<3.0.0)
|
34
34
|
Requires-Dist: ua-parser (>=0.18.0,<0.19.0)
|
35
35
|
Project-URL: Documentation, https://lacuscore.readthedocs.io/en/latest/
|
36
36
|
Project-URL: Repository, https://github.com/ail-project/LacusCore
|
@@ -1,10 +1,10 @@
|
|
1
1
|
lacuscore/__init__.py,sha256=hM4lKoPNybDCUMWdXTVVI1gRk_riLvRZ7IwFbamZLzE,341
|
2
2
|
lacuscore/helpers.py,sha256=lULN7HhY-4a4HG-ybIt4jO3wEGTxkm_jKNqsGpNZo4Y,2711
|
3
3
|
lacuscore/lacus_monitoring.py,sha256=UOfE_1-_rhVeKJXQ_m9XxYkr7VwyQnA6iK-x_tcXJfo,2775
|
4
|
-
lacuscore/lacuscore.py,sha256=
|
4
|
+
lacuscore/lacuscore.py,sha256=zi6oOcwmZ0yENIfJy55baeGXw3Js4lg5fmQz0YFRNJk,43030
|
5
5
|
lacuscore/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
6
|
lacuscore/task_logger.py,sha256=8WbdJdKnGeFCxt9gtCNLI9vAQQZbsy2I5PRQpHP7XFU,1916
|
7
|
-
lacuscore-1.9.
|
8
|
-
lacuscore-1.9.
|
9
|
-
lacuscore-1.9.
|
10
|
-
lacuscore-1.9.
|
7
|
+
lacuscore-1.9.4.dist-info/LICENSE,sha256=4C4hLYrIkUD96Ggk-y_Go1Qf7PBZrEm9PSeTGe2nd4s,1516
|
8
|
+
lacuscore-1.9.4.dist-info/METADATA,sha256=Lr1wGWp4zfC19UwS51sjTxznPywLBZ7-0e9rAF88cYs,2629
|
9
|
+
lacuscore-1.9.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
10
|
+
lacuscore-1.9.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|