python – cherrypy / dev / urandom(或等效)未找到 – 错误

我正在使用Python 2.5.1运行一个cherrypy 3.2.0服务器,它每隔几天就从UI的任何指令上发出以下错误,直到它被杀死并重新启动: –

[29/Mar/2012:06:37:57] HTTP Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 636, in respond
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 97, in run
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 57, in __call__
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 757, in init
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 162, in __init__
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 190, in _regenerate
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 204, in generate_id
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cpcompat.py", line 264, in random20
File "/usr/lib/python2.5/os.py", line 733, in urandom
NotImplementedError: /dev/urandom (or equivalent) not found

_cpcompat.py下面的一段代码表明,如果cherrypy无法读取/ dev / urandom,则random.random有一个回退,但似乎没有回退它.

try:
    os.urandom(20)
    import binascii
    def random20():
        return binascii.hexlify(os.urandom(20)).decode('ascii')

except (AttributeError, NotImplementedError):
    import random
    # os.urandom not available until Python 2.4. Fall back to random.random.
    def random20(): 
        return sha('%s' % random.random()).hexdigest()

以下是os.py的代码片段,与上下文相关: –

    如果不是_exists(“urandom”):

    def urandom(n):
        """urandom(n) -> str

        Return a string of n random bytes suitable for cryptographic use.

        """
        try:
            _urandomfd = open("/dev/urandom", O_RDONLY)
        except (OSError, IOError):
            raise NotImplementedError("/dev/urandom (or equivalent) not found")
        bytes = ""
        while len(bytes) < n:
            bytes += read(_urandomfd, n - len(bytes))
        close(_urandomfd)
        return bytes

在cherrypy无法读取/ dev / urandom的同时,以下代码片段工作正常: –

python -c“import os; fd = open(‘/ dev / urandom’,’r’); print fd.read(5); fd.close()”

我有两个问题: –

>当我能够从/ dev / urandom读取随机位时,为什么cherrypy throw没有实现错误
>当os.py引发NotImplementedError时,为什么_cpcompact.py没有执行except部分.

最佳答案
这也不是一个答案,但是,根据我的经验,这个NotImplementedError是错误的,但是当“太多文件”被打开时,多个处理过程开始抛出未捕获的异常后开始显示错误,留下来永远隐藏在子线程或子进程中.

我会开始进一步调试堆栈,看看是否有进程抛出的隐藏或静默异常

这是我开始看到此错误时的堆栈跟踪示例

Exception in thread Plotter:
Traceback (most recent call last):
  File "threading.pyc", line 532, in __bootstrap_inner
  File "plotters/edge.pyc", line 459, in run
  AttributeError: 'error' object has no attribute 'error'

OSError: [Errno 24] Too many open files
  File "multiprocessing/connection.pyc", line 150, in Client
  File "multiprocessing/connection.pyc", line 370, in deliver_challenge
    None
  File "os.pyc", line 756, in urandom
NotImplementedError: /dev/urandom (or equivalent) not found

我的AttributeError产生了,最终…… / urandom未找到imlp错误

转载注明原文:python – cherrypy / dev / urandom(或等效)未找到 – 错误 - 代码日志