Scrapy, a fast high-level web crawling & scraping framework for Python.
Raise an exception if ASYNCIO_ENABLED but the reactor is wrong.
Andrey Rakhmatullin8de80f59db19
diff --git a/scrapy/crawler.py b/scrapy/crawler.pyindex 706c8a59d..a9443f7ac 100644--- a/scrapy/crawler.py+++ b/scrapy/crawler.py@@ -14,7 +14,7 @@ from scrapy.extension import ExtensionManagerfrom scrapy.settings import overridden_settings, Settingsfrom scrapy.signalmanager import SignalManagerfrom scrapy.exceptions import ScrapyDeprecationWarning-from scrapy.utils.asyncio import install_asyncio_reactor+from scrapy.utils.asyncio import install_asyncio_reactor, is_asyncio_reactor_installedfrom scrapy.utils.ossignal import install_shutdown_handlers, signal_namesfrom scrapy.utils.misc import load_objectfrom scrapy.utils.log import (@@ -259,6 +259,10 @@ class CrawlerProcess(CrawlerRunner):super(CrawlerProcess, self).__init__(settings)if self.settings.getbool('ASYNCIO_ENABLED'):install_asyncio_reactor()+ if not is_asyncio_reactor_installed():+ raise Exception("ASYNCIO_ENABLED is on but the Twisted asyncio "+ "reactor is not installed, this is not supported.")+install_shutdown_handlers(self._signal_shutdown)configure_logging(self.settings, install_root_handler)log_scrapy_info(self.settings)diff --git a/scrapy/utils/log.py b/scrapy/utils/log.pyindex 0fe3d1549..6179e1bd1 100644--- a/scrapy/utils/log.py+++ b/scrapy/utils/log.py@@ -11,7 +11,6 @@ from twisted.python import log as twisted_logimport scrapyfrom scrapy.settings import Settingsfrom scrapy.exceptions import ScrapyDeprecationWarning-from scrapy.utils.asyncio import is_asyncio_reactor_installedfrom scrapy.utils.versions import scrapy_components_versions@@ -150,12 +149,7 @@ def log_scrapy_info(settings):for name, version in scrapy_components_versions()if name != "Scrapy")})if settings.getbool('ASYNCIO_ENABLED'):- if is_asyncio_reactor_installed():- logger.debug("Asyncio support enabled")- else:- logger.error("ASYNCIO_ENABLED is on but the Twisted asyncio "- "reactor is not installed, this is not supported "- "and asyncio coroutines will not work.")+ logger.debug("Asyncio support enabled")class StreamLogger(object):diff --git a/tests/test_crawler.py b/tests/test_crawler.pyindex 0b2645280..a2865fcd1 100644--- a/tests/test_crawler.py+++ b/tests/test_crawler.py@@ -264,13 +264,14 @@ class CrawlerRunnerHasSpider(unittest.TestCase):@defer.inlineCallbacksdef test_crawler_process_asyncio_enabled_true(self):with LogCapture(level=logging.DEBUG) as log:- runner = CrawlerProcess(settings={'ASYNCIO_ENABLED': True})- yield runner.crawl(NoRequestsSpider)if self.reactor_pytest == 'asyncio':+ runner = CrawlerProcess(settings={'ASYNCIO_ENABLED': True})+ yield runner.crawl(NoRequestsSpider)self.assertIn("Asyncio support enabled", str(log))else:- self.assertNotIn("Asyncio support enabled", str(log))- self.assertIn("ASYNCIO_ENABLED is on but the Twisted asyncio reactor is not installed", str(log))+ msg = "ASYNCIO_ENABLED is on but the Twisted asyncio reactor is not installed"+ with self.assertRaisesRegex(Exception, msg):+ runner = CrawlerProcess(settings={'ASYNCIO_ENABLED': True})@defer.inlineCallbacksdef test_crawler_process_asyncio_enabled_false(self):