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

This commit is contained in:
Pablo Hoffman 2011-06-06 03:12:40 -03:00
parent 35b52fcdf0
commit 5fbc32c015
3 changed files with 6 additions and 2 deletions

View File

@ -185,6 +185,10 @@ class (which they all inherit from).
for this spider can be accessed. This method is called automatically on
the :signal:`spider_closed` signal.
.. method:: engine_stopped()
Called after the engine is stopped, to dump or persist global stats.
Available Stats Collectors
==========================

View File

@ -260,3 +260,4 @@ class ExecutionEngine(object):
@defer.inlineCallbacks
def _finish_stopping_engine(self):
yield send_catch_log_deferred(signal=signals.engine_stopped)
yield stats.engine_stopped()

View File

@ -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))