Scrapy, a fast high-level web crawling & scraping framework for Python.
avoid random "Interrupted system call" errors
Pablo Hoffman6217f108cce8
diff --git a/scrapy/tests/test_commands.py b/scrapy/tests/test_commands.pyindex 449dcfe1c..2495a0123 100644--- a/scrapy/tests/test_commands.py+++ b/scrapy/tests/test_commands.py@@ -7,6 +7,8 @@ from tempfile import mkdtempfrom twisted.trial import unittest+from scrapy.utils.python import retry_on_eintr+class ProjectTest(unittest.TestCase):project_name = 'testproject'@@ -75,11 +77,11 @@ class GenspiderCommandTest(CommandTest):args = ['--template=%s' % tplname] if tplname else []spname = 'test_spider'p = self.proc('genspider', spname, 'test.com', *args)- out = p.stdout.read()+ out = retry_on_eintr(p.stdout.read)self.assert_("Created spider %r using template %r in module" % (spname, tplname) in out)self.assert_(exists(join(self.proj_mod_path, 'spiders', 'test_spider.py')))p = self.proc('genspider', spname, 'test.com', *args)- out = p.stdout.read()+ out = retry_on_eintr(p.stdout.read)self.assert_("Spider %r already exists in module" % spname in out)def test_template_basic(self):diff --git a/scrapy/utils/python.py b/scrapy/utils/python.pyindex 82c953abc..7cd02234e 100644--- a/scrapy/utils/python.py+++ b/scrapy/utils/python.py@@ -9,6 +9,7 @@ import osimport reimport inspectimport weakref+import errnofrom functools import wrapsfrom sgmllib import SGMLParser@@ -222,3 +223,13 @@ def setattr_default(obj, name, value):"""if not hasattr(obj, name):setattr(obj, name, value)+++def retry_on_eintr(function, *args, **kw):+ """Run a function and retry it while getting EINTR errors"""+ while True:+ try:+ return function(*args, **kw)+ except IOError, e:+ if e.errno != errno.EINTR:+ raise