I could need some enlightment here. I'm currently using a combination
of restkit, lxml and gevent for a botlike tool, but when I tried to
group some functionality of the downloading and the processing
together, I got some strange deadlocks, which I strapped down to the
following testcase. wrapper_working does it's job as expected, adding
more functionality from lxml there, gets the deadlock. Any ideas, why
that is going wrong, and how I could get the wrapper_failing to work,
without taking the functionality out of the wrapper, would be greatly
appreciated.
Thanks!
Michael
from gevent import monkey, pool
monkey.patch_all()
import logging
import unittest
import restkit
from lxml import etree
class DSmassDLTest(unittest.TestCase):
parser = etree.HTMLParser()
test_urls = [
"http://yahoo.fr",
"http://google.com",
"http://friendpaste.com",
"http://benoitc.io",
"http://couchdb.apache.org"]
@staticmethod
def wrapper_failing(args):
ret = args[0](*args[1], **args[2])
tree = etree.ElementTree(file=ret.body_stream(),
parser=DSmassDLTest.parser)
logging.info("Got: %s", tree.xpath('//title')[0].text.strip())
@staticmethod
def wrapper_working(args):
return args[0](*args[1], **args[2])
def runTest(self):
wrapper = DSmassDLTest.wrapper_working
funcs = (restkit.request,) * len(self.test_urls)
args = tuple((url,) for url in self.test_urls)
kwargs = (dict(follow_redirect=True),) * len(self.test_urls)
data = zip(funcs, args, kwargs) * 3
gp = pool.Group()
dls = gp.imap(wrapper, data)
if wrapper == DSmassDLTest.wrapper_working:
for dl in dls:
tree = etree.ElementTree(file=dl.body_stream(),
parser=DSmassDLTest.parser)
logging.info("Got: %s", tree.xpath('//title')
[0].text.strip())
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
suite = unittest.TestSuite()
suite.addTest(DSmassDLTest())
unittest.TextTestRunner(verbosity=2).run(suite)
any trace or something? Also apparently you are not using a gevent
restkit pool, which is needed.
- benoit
thanks for your answer. It doesn't crash with a trace, the program just
freezes and is not responsive anymore.
So you mean, restkit should get a separate pool? Could you please more
specific, what exactly would have to be changed?
In the non-strapped application I had used GeventManager, but the result
was the same, to I tried to reduce it even more,
as too many connections don't seem to be the issue here.
logging.info("Got: %s", tree.xpath('//title')[0].text.strip())
Hi Benoit,thanks for your answer. It doesn't crash with a trace, the program just
freezes and is not responsive anymore.So you mean, restkit should get a separate pool? Could you please more
specific, what exactly would have to be changed?In the non-strapped application I had used GeventManager, but the result
was the same, to I tried to reduce it even more,
as too many connections don't seem to be the issue here.
Am 14.12.2011 18:42, schrieb Benoit Chesneau: