Test Slot's heartbeat state before stopping it

Also add a test on state of looping task in LogStats extension

Fixes #2011 and #2362
This commit is contained in:
Paul Tremberth 2016-11-07 16:44:57 +01:00
parent 0f5eb4cf88
commit 7727d87f64
2 changed files with 4 additions and 2 deletions

View File

@ -48,7 +48,8 @@ class Slot(object):
if self.closing and not self.inprogress:
if self.nextcall:
self.nextcall.cancel()
self.heartbeat.stop()
if self.heartbeat.running:
self.heartbeat.stop()
self.closing.callback(None)

View File

@ -15,6 +15,7 @@ class LogStats(object):
self.stats = stats
self.interval = interval
self.multiplier = 60.0 / self.interval
self.task = None
@classmethod
def from_crawler(cls, crawler):
@ -47,5 +48,5 @@ class LogStats(object):
logger.info(msg, log_args, extra={'spider': spider})
def spider_closed(self, spider, reason):
if self.task.running:
if self.task and self.task.running:
self.task.stop()