Scrapy, a fast high-level web crawling & scraping framework for Python.
call stats collector engine_stopped() after the engine is closed (to make sure all data from extensions has been collected), and added that method to documented api
Pablo Hoffman5fbc32c0156a
diff --git a/docs/topics/stats.rst b/docs/topics/stats.rstindex 072164e5b..69b08211f 100644--- a/docs/topics/stats.rst+++ b/docs/topics/stats.rst@@ -185,6 +185,10 @@ class (which they all inherit from).for this spider can be accessed. This method is called automatically onthe :signal:`spider_closed` signal.+ .. method:: engine_stopped()++ Called after the engine is stopped, to dump or persist global stats.+Available Stats Collectors==========================diff --git a/scrapy/core/engine.py b/scrapy/core/engine.pyindex 994bd70cd..ec433ad0f 100644--- a/scrapy/core/engine.py+++ b/scrapy/core/engine.py@@ -260,3 +260,4 @@ class ExecutionEngine(object):@defer.inlineCallbacksdef _finish_stopping_engine(self):yield send_catch_log_deferred(signal=signals.engine_stopped)+ yield stats.engine_stopped()diff --git a/scrapy/statscol.py b/scrapy/statscol.pyindex c69510dd0..b4ecb2f05 100644--- a/scrapy/statscol.py+++ b/scrapy/statscol.py@@ -17,7 +17,6 @@ class StatsCollector(object):def __init__(self):self._dump = settings.getbool('STATS_DUMP')self._stats = {None: {}} # None is for global stats- dispatcher.connect(self._engine_stopped, signal=signals.engine_stopped)def get_value(self, key, default=None, spider=None):return self._stats[spider].get(key, default)@@ -63,7 +62,7 @@ class StatsCollector(object):spider=spider)self._persist_stats(stats, spider)- def _engine_stopped(self):+ def engine_stopped(self):stats = self.get_stats()if self._dump:log.msg("Dumping global stats:\n" + pprint.pformat(stats))