- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个相当简单、朴素的 Python/WSGI/Pyramid 网络服务器。
它在使用 pyramid.config.Configurator().make_wsgi_app()
构建的服务器上使用 wsgiref.simple_server.make_server()
运行。该服务器工作正常。
但是,它所服务的应用程序有很多 javascript 图像鼠标悬停弹出窗口。如果您在页面上运行鼠标,它可以生成 20 多个图像请求。这也很好(这是内部的事情,不是很多用户)。
但是,这样做会导致服务器发出类似六个错误回溯的信息:
10.1.1.4 - - [25/Apr/2014 01:56:42] "GET /*SNIP* 500 59
----------------------------------------
Exception happened during processing of request from ('10.1.1.4', 18338)
Traceback (most recent call last):
File "/usr/lib/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib/python3.4/wsgiref/handlers.py", line 333, in send_headers
self._write(bytes(self.headers))
File "/usr/lib/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib/python3.4/socket.py", line 391, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/wsgiref/handlers.py", line 141, in run
self.handle_error()
File "/usr/lib/python3.4/wsgiref/handlers.py", line 368, in handle_error
self.finish_response()
File "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib/python3.4/wsgiref/handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "/usr/lib/python3.4/wsgiref/handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/socketserver.py", line 306, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python3.4/socketserver.py", line 332, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python3.4/socketserver.py", line 345, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.4/socketserver.py", line 666, in __init__
self.handle()
File "/usr/lib/python3.4/wsgiref/simple_server.py", line 126, in handle
handler.run(self.server.get_app())
File "/usr/lib/python3.4/wsgiref/handlers.py", line 144, in run
self.close()
File "/usr/lib/python3.4/wsgiref/simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
我明白为什么我遇到管道错误(图像请求在图像完全传输之前被取消,因为鼠标悬停弹出窗口已关闭),这似乎无害。
但是,我不知道如何让这个回溯沉默。我的日志中有成千上万个错误,这让调试实际错误成为一场噩梦。我不在乎我遇到管道错误,我怎样才能捕捉到它们并静静地吞下它们?
似乎 wsgiref.simple_server.make_server()
安装了一个内部处理程序来捕获 BrokenPipeError: [Errno 32] Broken pipe
,打印回溯,然后吞下错误。我试过将 run_server()
调用包装在 try-except 子句中,但它没有任何效果。
最佳答案
我最后转而使用 CherryPy WSGI Server .它不会遭受管道日志损坏问题的困扰,而且可能也更加健壮。
它还使用线程池,因此性能也更高(多个请求不会阻塞!)。
关于wsgi - 使用 WSGI+Pyramid 在 python 中静音破损的管道错误 (`[Errno 32] Broken pipe`),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23288712/
我是一名优秀的程序员,十分优秀!