avoid random "Interrupted system call" errors

This commit is contained in:
Pablo Hoffman 2012-08-29 11:44:00 -03:00
parent 8aa46a4b5d
commit 6217f108cc
2 changed files with 15 additions and 2 deletions

View File

@ -7,6 +7,8 @@ from tempfile import mkdtemp
from 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):

View File

@ -9,6 +9,7 @@ import os
import re
import inspect
import weakref
import errno
from functools import wraps
from 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