{"action":"created","issue":{"url":"https://api.github.com/repos/scrapy/scrapy/issues/1129","labels_url":"https://api.github.com/repos/scrapy/scrapy/issues/1129/labels{/name}","comments_url":"https://api.github.com/repos/scrapy/scrapy/issues/1129/comments","events_url":"https://api.github.com/repos/scrapy/scrapy/issues/1129/events","html_url":"https://github.com/scrapy/scrapy/issues/1129","id":65872488,"number":1129,"title":"cannot yield item in forsubfunction of parse process","user":{"login":"suemi994","id":8297167,"avatar_url":"https://avatars.githubusercontent.com/u/8297167?v=3","gravatar_id":"","url":"https://api.github.com/users/suemi994","html_url":"https://github.com/suemi994","followers_url":"https://api.github.com/users/suemi994/followers","following_url":"https://api.github.com/users/suemi994/following{/other_user}","gists_url":"https://api.github.com/users/suemi994/gists{/gist_id}","starred_url":"https://api.github.com/users/suemi994/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suemi994/subscriptions","organizations_url":"https://api.github.com/users/suemi994/orgs","repos_url":"https://api.github.com/users/suemi994/repos","events_url":"https://api.github.com/users/suemi994/events{/privacy}","received_events_url":"https://api.github.com/users/suemi994/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-02T08:02:55Z","updated_at":"2015-04-02T12:11:29Z","closed_at":null,"body":"Here I will give a example:\r\n\r\n```python\r\nclass HiapkSpider(scrapy.spider.Spider):\r\n    name=\"hiapk\"\r\n    allowed_domains=['apk.hiapk.com']\r\n\r\n    def __init__(self,start=1,end=2):\r\n        self.prefix_url=\"http://apk.hiapk.com/apps?sort=5&pi=\"\r\n        self.base_url=\"http://apk.hiapk.com\"\r\n        self.prefix_path=\"../temp/\"\r\n        self.page_start=int(start)\r\n        self.page_index=self.page_start\r\n        self.page_end=int(end)\r\n        HiapkSpider.start_urls=[self.prefix_url+str(self.page_start)]\r\n\r\n    def parse(self,response):\r\n        self.apkList=[]\r\n        if self.page_index > self.page_end:\r\n            print 'Spider Completed'\r\n            return\r\n        for sel in response.xpath('//li[contains(@class,\"list_item\")]'):\r\n            item=ApkItem()\r\n            item['name']=sel.xpath('div/dl/dt/span/a/@href').extract()[0].split('.')[-1]\r\n            item['version']=sel.xpath('div/dl/dt/*[2]/text()').extract()[0][1:-1]\r\n            item['url']=self.base_url+sel.xpath('div/*[3]/a/@href').extract()[0]\r\n            item['path']=self.prefix_path+item['name']+'.apk'\r\n            self.apkList.append(item)\r\n        self.download()\r\n        self.page_index+=1\r\n        for item in self.apkList:\r\n            yield item\r\n        yield Request(self.prefix_url+str(self.page_index),\r\n                      callback=self.parse)\r\n\r\n\r\n    def download(self):\r\n        print 'DownLoad Start'\r\n        p=Pool()\r\n        result=[]\r\n        for item in self.apkList:\r\n           # tmp=p.apply_async(urllib.urlretrieve,[item['url'],item['path']])\r\n           tmp=p.apply_async(kkk,[2])\r\n           result.append(tmp)\r\n        p.close()\r\n        p.join()\r\n        for i in range(0,len(self.apkList)):\r\n            try:\r\n                print result[i].get()\r\n            except:\r\n                continue\r\n            else:\r\n                yield self.apkList[i]\r\n```\r\n\r\nif I use yield in the for stucture of download function , this function will not be excuted. But if I yield directly in download function, all right. Very strange!"},"comment":{"url":"https://api.github.com/repos/scrapy/scrapy/issues/comments/88880080","html_url":"https://github.com/scrapy/scrapy/issues/1129#issuecomment-88880080","issue_url":"https://api.github.com/repos/scrapy/scrapy/issues/1129","id":88880080,"user":{"login":"nyov","id":438293,"avatar_url":"https://avatars.githubusercontent.com/u/438293?v=3","gravatar_id":"","url":"https://api.github.com/users/nyov","html_url":"https://github.com/nyov","followers_url":"https://api.github.com/users/nyov/followers","following_url":"https://api.github.com/users/nyov/following{/other_user}","gists_url":"https://api.github.com/users/nyov/gists{/gist_id}","starred_url":"https://api.github.com/users/nyov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyov/subscriptions","organizations_url":"https://api.github.com/users/nyov/orgs","repos_url":"https://api.github.com/users/nyov/repos","events_url":"https://api.github.com/users/nyov/events{/privacy}","received_events_url":"https://api.github.com/users/nyov/received_events","type":"User","site_admin":false},"created_at":"2015-04-02T12:11:29Z","updated_at":"2015-04-02T12:11:29Z","body":"You must also return or yield the called sub function, so the returned value does not get lost:\r\n`self.download()` should be `yield self.download()`, I believe."}}