stats.get_value('myvariable') returns None when myvariable is not updated #136

Closed
tsouras opened this Issue May 20, 2012 · 2 comments

Comments

Projects
None yet
3 participants

tsouras commented May 20, 2012

Lets say I create a statistics variable in a spider and then I use it in a pipeline.

class XXXSpider(BaseSpider):
    name = "xxx"
    allowed_domains = ["http://xxx.com"]

    def start_requests(self):
         stats.set_value('myvariable', 0, spider=self)
         bla
         bla


class MyPipeline(object):     
    def close_spider(self, spider):
        myvariable=stats.get_value('myvariable', spider=spider)
        print myvariable

If "myvariable" is not changed at all then stats.get_value('myvariable', spider=spider) returns None.
If somewhere in the code I update myvariable using the function stats.inc_value('done_matches', spider=myspider) then stats.get_value('myvariable', spider=spider) returns a number correctly.

My system is the following:
Scrapy : 0.14.3
Twisted : 11.0.0
Python : 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)]
Platform: Windows-XP-5.1.2600-SP3

Owner

pablohoffman commented May 21, 2012

Are you sure the stats.set_value('myvariable', 0, spider=self) is getting called?. Try adding a print to check.

Owner

dangra commented Jan 29, 2013

dusty

dangra closed this Jan 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment