class MySpider(CrawlSpider):

    def __init__(self):
        dispatcher.connect(self.spider_closed, signals.spider_closed)

def spider_closed(self, spider):
    pass
scrapy: Call a function when a spider quits