Scrapy, a fast high-level web crawling & scraping framework for Python.
Make AiohttpDownloadHandler lazy (#8346)
Adrianc1d010deb31f
diff --git a/docs/topics/download-handlers.rst b/docs/topics/download-handlers.rstindex 9159467eb..5ffeb8d03 100644--- a/docs/topics/download-handlers.rst+++ b/docs/topics/download-handlers.rst@@ -245,10 +245,13 @@ AiohttpDownloadHandler.. versionadded:: 2.19.0+.. versionchanged:: VERSION+ In earlier versions, the handler was not lazy.+.. autoclass:: scrapy.core.downloader.handlers._aiohttp.AiohttpDownloadHandler| Supported schemes: ``http``, ``https``.-| :ref:`Lazy <lazy-download-handlers>`: no.+| :ref:`Lazy <lazy-download-handlers>`: yes.| :ref:`Requires asyncio support <using-asyncio>`: yes.| :ref:`Requires a Twisted reactor <asyncio-without-reactor>`: no.diff --git a/scrapy/core/downloader/handlers/_aiohttp.py b/scrapy/core/downloader/handlers/_aiohttp.pyindex 3317ffbbe..741532320 100644--- a/scrapy/core/downloader/handlers/_aiohttp.py+++ b/scrapy/core/downloader/handlers/_aiohttp.py@@ -51,6 +51,7 @@ class _ClientResponse(aiohttp.ClientResponse):class AiohttpDownloadHandler(BaseStreamingDownloadHandler[_ClientResponse]):experimental: ClassVar[bool] = True+ lazy = Truedef __init__(self, crawler: Crawler):super().__init__(crawler)diff --git a/tests/test_crawler_subprocess.py b/tests/test_crawler_subprocess.pyindex de3d00813..0b564e352 100644--- a/tests/test_crawler_subprocess.py+++ b/tests/test_crawler_subprocess.py@@ -416,8 +416,7 @@ class TestAsyncCrawlerProcessSubprocess(TestCrawlerProcessSubprocessBase):assert "Spider closed (finished)" in logassert "is_reactorless(): True" in logassert "ERROR: " not in log- assert log.count("WARNING: AiohttpDownloadHandler is experimental") == 2- assert log.count("WARNING: ") == 2+ assert "WARNING: " not in logdef test_reactorless_custom_settings(self) -> None:"""Setting TWISTED_REACTOR_ENABLED=False in spider settings is not@@ -438,8 +437,7 @@ class TestAsyncCrawlerProcessSubprocess(TestCrawlerProcessSubprocessBase):assert "{'data': 'foo'}" in logassert "'item_scraped_count': 1" in logassert "ERROR: " not in log- assert log.count("WARNING: AiohttpDownloadHandler is experimental") == 2- assert log.count("WARNING: ") == 2+ assert "WARNING: " not in logdef test_reactorless_import_hook(self) -> None:log = self.run_script("reactorless_import_hook.py")@@ -669,8 +667,7 @@ class TestAsyncCrawlerRunnerSubprocess(TestCrawlerRunnerSubprocessBase):assert "Spider closed (finished)" in logassert "is_reactorless(): True" in logassert "ERROR: " not in log- assert log.count("WARNING: AiohttpDownloadHandler is experimental") == 2- assert log.count("WARNING: ") == 2+ assert "WARNING: " not in logdef test_reactorless_loop_not_running(self) -> None:log = self.run_script("reactorless_loop_not_running.py")@@ -696,8 +693,7 @@ class TestAsyncCrawlerRunnerSubprocess(TestCrawlerRunnerSubprocessBase):assert "{'data': 'foo'}" in logassert "'item_scraped_count': 1" in logassert "ERROR: " not in log- assert log.count("WARNING: AiohttpDownloadHandler is experimental") == 2- assert log.count("WARNING: ") == 2+ assert "WARNING: " not in logdef test_reactorless_reactor(self) -> None:log = self.run_script("reactorless_reactor.py")