mirror of https://github.com/scrapy/scrapy.git
Fixed exception thrown when in FreeBSD when /proc exists but it's not mounted. Closes #235
This commit is contained in:
parent
b16eff227b
commit
e7a958a035
|
|
@ -4,7 +4,6 @@ MemoryUsage extension
|
|||
See documentation in docs/topics/extensions.rst
|
||||
"""
|
||||
|
||||
import os
|
||||
import socket
|
||||
from pprint import pformat
|
||||
|
||||
|
|
@ -18,7 +17,7 @@ from scrapy.exceptions import NotConfigured
|
|||
from scrapy.mail import MailSender
|
||||
from scrapy.conf import settings
|
||||
from scrapy.stats import stats
|
||||
from scrapy.utils.memory import get_vmvalue_from_procfs
|
||||
from scrapy.utils.memory import get_vmvalue_from_procfs, procfs_supported
|
||||
from scrapy.utils.engine import get_engine_status
|
||||
|
||||
class MemoryUsage(object):
|
||||
|
|
@ -26,7 +25,7 @@ class MemoryUsage(object):
|
|||
def __init__(self):
|
||||
if not settings.getbool('MEMUSAGE_ENABLED'):
|
||||
raise NotConfigured
|
||||
if not os.path.exists('/proc'):
|
||||
if not procfs_supported():
|
||||
raise NotConfigured
|
||||
|
||||
self.warned = False
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
import os
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from scrapy.utils.memory import get_vmvalue_from_procfs
|
||||
from scrapy.utils.memory import get_vmvalue_from_procfs, procfs_supported
|
||||
|
||||
class UtilsMemoryTestCase(unittest.TestCase):
|
||||
|
||||
def test_get_vmvalue_from_procfs(self):
|
||||
if not os.path.exists('/proc'):
|
||||
if not procfs_supported():
|
||||
raise unittest.SkipTest('/proc filesystem not supported')
|
||||
vmsize = get_vmvalue_from_procfs('VmSize')
|
||||
vmrss = get_vmvalue_from_procfs('VmRSS')
|
||||
|
|
|
|||
|
|
@ -23,3 +23,10 @@ def get_vmvalue_from_procfs(vmkey='VmSize', pid=None):
|
|||
# convert Vm value to bytes
|
||||
return int(v[1]) * _vmvalue_scale[v[2]]
|
||||
|
||||
def procfs_supported():
|
||||
try:
|
||||
open('/proc/%d/status' % os.getpid())
|
||||
except IOError:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
|
|
|||
Loading…
Reference in New Issue