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

hal*_*tTm 5 python random session cherrypy

我运行的CherryPy 3.2.0服务器与Python 2.5.1,它提供了以下错误每隔几天从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
Run Code Online (Sandbox Code Playgroud)

_cpcompat.py有一段代码表明,random.random如果cherrypy无法读取/dev/urandom,但似乎没有倒退,则会出现回落.

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()
Run Code Online (Sandbox Code Playgroud)

os.py上下文相关的代码片段: -

if not _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
Run Code Online (Sandbox Code Playgroud)

/dev/urandom

python -c "import os;fd = open('/dev/urandom', 'r');print fd.read(5);fd.close()" ,以下代码片段工作正常: -

_cpcompact.py

我有两个问题: -

  1. 当我能够从/ dev/urandom读取随机位时,为什么cherrypy throw没有实现错误
  2. 为什么os.pyNotImplementedError提升时不执行除部分_cpcompat.py.

小智 4

这也不是一个答案,但是,根据我的经验,这个 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
Run Code Online (Sandbox Code Playgroud)

我的 AttributeError 最终产生了... /urandom not found imlp 错误