Skip to content

Commit c1ea881

Browse files
committed
fix: Set default desired concurrency for non-browser crawlers to 10
1 parent 6f1752e commit c1ea881

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/crawlee/_types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ class ConcurrencySettings:
110110
def __init__(
111111
self,
112112
min_concurrency: int = 1,
113-
max_concurrency: int = 200,
113+
max_concurrency: int = 100,
114114
max_tasks_per_minute: float = float('inf'),
115-
desired_concurrency: int | None = None,
115+
desired_concurrency: int = 10,
116116
) -> None:
117117
"""Initialize a new instance.
118118
@@ -125,21 +125,21 @@ def __init__(
125125
desired_concurrency: The desired number of tasks that should be running parallel on the start of the pool,
126126
if there is a large enough supply of them. By default, it is `min_concurrency`.
127127
"""
128-
if desired_concurrency is not None and desired_concurrency < 1:
129-
raise ValueError('desired_concurrency must be 1 or larger')
130-
131128
if min_concurrency < 1:
132129
raise ValueError('min_concurrency must be 1 or larger')
133130

134131
if max_concurrency < min_concurrency:
135132
raise ValueError('max_concurrency cannot be less than min_concurrency')
136133

134+
if desired_concurrency < min_concurrency:
135+
raise ValueError('desired_concurrency cannot be less than min_concurrency')
136+
137137
if max_tasks_per_minute <= 0:
138138
raise ValueError('max_tasks_per_minute must be positive')
139139

140140
self.min_concurrency = min_concurrency
141141
self.max_concurrency = max_concurrency
142-
self.desired_concurrency = desired_concurrency if desired_concurrency is not None else min_concurrency
142+
self.desired_concurrency = desired_concurrency
143143
self.max_tasks_per_minute = max_tasks_per_minute
144144

145145

src/crawlee/crawlers/_adaptive_playwright/_adaptive_playwright_crawler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from parsel import Selector
1313
from typing_extensions import Self, TypeVar, override
1414

15-
from crawlee._types import BasicCrawlingContext, JsonSerializable, RequestHandlerRunResult
15+
from crawlee._types import BasicCrawlingContext, ConcurrencySettings, JsonSerializable, RequestHandlerRunResult
1616
from crawlee._utils.docs import docs_group
1717
from crawlee._utils.wait import wait_for
1818
from crawlee.crawlers import (
@@ -158,6 +158,10 @@ def __init__(
158158
self.result_checker = result_checker or (lambda _: True)
159159
self.result_comparator = result_comparator or create_default_comparator(result_checker)
160160

161+
# Set default concurrency settings for browser crawlers if not provided
162+
if 'concurrency_settings' not in kwargs or kwargs['concurrency_settings'] is None:
163+
kwargs['concurrency_settings'] = ConcurrencySettings(desired_concurrency=1)
164+
161165
super().__init__(statistics=statistics, **kwargs)
162166

163167
# Sub crawlers related.

src/crawlee/crawlers/_basic/_basic_crawler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from crawlee._service_locator import ServiceLocator
3131
from crawlee._types import (
3232
BasicCrawlingContext,
33+
ConcurrencySettings,
3334
EnqueueLinksKwargs,
3435
GetKeyValueStoreFromRequestHandlerFunction,
3536
HttpHeaders,
@@ -75,7 +76,6 @@
7576
from contextlib import AbstractAsyncContextManager
7677

7778
from crawlee._types import (
78-
ConcurrencySettings,
7979
EnqueueLinksFunction,
8080
ExtractLinksFunction,
8181
GetDataKwargs,

src/crawlee/crawlers/_playwright/_playwright_crawler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from crawlee import service_locator
1414
from crawlee._request import Request, RequestOptions
15+
from crawlee._types import ConcurrencySettings
1516
from crawlee._utils.blocked import RETRY_CSS_SELECTORS
1617
from crawlee._utils.docs import docs_group
1718
from crawlee._utils.robots import RobotsTxtFile
@@ -194,6 +195,10 @@ def __init__(
194195

195196
kwargs['http_client'] = PlaywrightHttpClient() if not kwargs.get('http_client') else kwargs['http_client']
196197

198+
# Set default concurrency settings for browser crawlers if not provided
199+
if 'concurrency_settings' not in kwargs or kwargs['concurrency_settings'] is None:
200+
kwargs['concurrency_settings'] = ConcurrencySettings(desired_concurrency=1)
201+
197202
super().__init__(**kwargs)
198203

199204
async def _open_page(

0 commit comments

Comments
 (0)