scrapy: spider destructor (__del__) never executed
Question: I have created an scrapy spider that works well (it does what is supposed to
do), but when finish working it doesn't execute the destructor code (**del**)

Versions are: \- python 2.7.3 \- scrapy 0.24.6 \- Fedora 18

    
    
    class MySpider(scrapy.Spider):
    stuff
    def __del__(self):
        stuff_1
    

How could I execute my "stuff-1" code when MySpider is done?


Answer: Use signals. In particular,
[`spider_closed`](http://doc.scrapy.org/en/latest/topics/signals.html#scrapy.signals.spider_closed)
signal:

    
    
    from scrapy import signals
    from scrapy.xlib.pydispatch import dispatcher
    
    class MySpider(scrapy.Spider):
        def __init__(self):
            dispatcher.connect(self.spider_closed, signals.spider_closed)
    
        def spider_closed(self, spider):
            stuff_1()
    

