From 3a71504d35a5e5b9eacf29c63c9a317f5167e3db Mon Sep 17 00:00:00 2001 From: Julia Medina Date: Fri, 24 Apr 2015 18:30:00 -0300 Subject: [PATCH] Extend CrawlerProcess documentation --- docs/topics/api.rst | 4 ++++ scrapy/crawler.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/topics/api.rst b/docs/topics/api.rst index 5d28b3c90..ce28b8bc1 100644 --- a/docs/topics/api.rst +++ b/docs/topics/api.rst @@ -102,6 +102,10 @@ how you :ref:`configure the downloader middlewares .. autoclass:: CrawlerRunner :members: +.. autoclass:: CrawlerProcess + :show-inheritance: + :members: + :inherited-members: .. _topics-api-settings: diff --git a/scrapy/crawler.py b/scrapy/crawler.py index 9680f6e11..161ca4614 100644 --- a/scrapy/crawler.py +++ b/scrapy/crawler.py @@ -185,7 +185,24 @@ class CrawlerRunner(object): class CrawlerProcess(CrawlerRunner): - """A class to run multiple scrapy crawlers in a process simultaneously""" + """ + A class to run multiple scrapy crawlers in a process simultaneously. + + This class extends :class:`~scrapy.crawler.CrawlerRunner` by adding support + for starting a Twisted `reactor`_ and handling shutdown signals, like the + keyboard interrupt command Ctrl-C. It also configures top-level logging. + + This utility should be a better fit than + :class:`~scrapy.crawler.CrawlerRunner` if you aren't running another + Twisted `reactor`_ within your application. + + The CrawlerProcess object must be instantiated with a + :class:`~scrapy.settings.Settings` object. + + This class shouldn't be needed (since Scrapy is responsible of using it + accordingly) unless writing scripts that manually handle the crawling + process. See :ref:`run-from-script` for an example. + """ def __init__(self, settings): super(CrawlerProcess, self).__init__(settings) @@ -209,6 +226,17 @@ class CrawlerProcess(CrawlerRunner): reactor.callFromThread(self._stop_reactor) def start(self, stop_after_crawl=True): + """ + This method starts a Twisted `reactor`_, adjusts its pool size to + :setting:`REACTOR_THREADPOOL_MAXSIZE`, and installs a DNS cache based + on :setting:`DNSCACHE_ENABLED` and :setting:`DNSCACHE_SIZE`. + + If `stop_after_crawl` is True, the reactor will be stopped after all + crawlers have finished, using :meth:`join`. + + :param boolean stop_after_crawl: stop or not the reactor when all + crawlers have finished + """ if stop_after_crawl: d = self.join() # Don't start the reactor if the deferreds are already fired