'Close a spider being scraped and release its resources'

def close_spider(self, spider):

    slot = self.slot
    slot.closing = defer.Deferred()
    slot.closing.addCallback(self.itemproc.close_spider)
    self._check_if_closing(spider, slot)
    return slot.closing
