1

我正在使用guvfeedparser同时解析多个提要。以下是我的代码:

guv.monkey_patch(time=True, socket=True)

def parse_feed(_feed):  
    return feedparser.parse(_feed)

def main():
    urls = ["http://feeds.bbci.co.uk/news/rss.xml"]
    pool = guv.GreenPool()
    results = pool.starmap(parse_feed, zip(urls))
    for resp in results:
        print(str(resp)) 

但是,我得到以下输出:

{'bozo_exception': TypeError('a float is required',), 'bozo': 1, 'feed': {}, 'entries': []}

我在使用时遇到了类似的问题Eventlet,但在本机 Python 3threading库中没有。

4

1 回答 1

0

I'm not able to install the guv module locally, so I can't test your code verbatim, but if I use eventlet.greenpool.GreenPool instead everything works fine:

import feedparser
import eventlet.greenpool

def parse_feed(_feed):  
    print 'PARSE:', _feed
    return feedparser.parse(_feed)

def main():
    urls = ["http://feeds.bbci.co.uk/news/rss.xml"]
    pool = eventlet.greenpool.GreenPool()
    results = pool.starmap(parse_feed, zip(urls))
    for resp in results:
        print resp

main()

I also see correct behavior with itertools.starmap(). Is it possible you're seeing some sort of transient error?

于 2015-05-06T20:29:16.273 回答