我正在使用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无法读取random.random
,/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()
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
if not _exists("urandom"):
在cherrypy无法阅读 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
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
的同时,以下代码段工作正常: -
我有两个问题: -
/dev/urandom
提出
python -c "import os;fd = open('/dev/urandom', 'r');print fd.read(5);fd.close()"
时,为什么_cpcompact.py
没有执行除外部分。答案 0 :(得分: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
我的AttributeError产生,最终...... / urandom未找到imlp错误
答案 1 :(得分:1)
这不是一个答案,但也许您可以将一些调试代码放入os.py
(我无法想象它会影响使用import os
的任何其他程序,但它值得记住它的自定义)< / p>
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)
# debug changes
except (OSError, IOError) as Err:
import syslog
syslog.syslog(repr(Err))
# /debug
raise NotImplementedError("/dev/urandom (or equivalent) not found")
bytes = ""
while len(bytes) < n:
bytes += read(_urandomfd, n - len(bytes))
close(_urandomfd)
return bytes
希望这能告诉你错误是什么。 (当然,您只需要写入文件等替换syslog)
答案 2 :(得分:0)
如果您的系统没有创建/ dev / random和/ dev / urandom,可以使用以下命令创建它们:
mknod -m 644 / dev / random c 1 8
mknod -m 644 / dev / urandom c 1 9
chown root:root / dev / random / dev / urandom