我有一个webApp我一直在努力,我注意到每隔一段时间我就会看到错误“线程CP服务器线程中的异常 - *”,其中* =随机线程数。这个错误偶尔会发生,最终会发生锁定Web服务器,阻止它响应请求。
我能够使用CherryPy来支持SSL,使用默认的“hello World”webPy应用程序重现相同的问题。
import web
from web.wsgiserver import CherryPyWSGIServer
# GLOBALS
CherryPyWSGIServer.ssl_certificate = "/.ssl/fpi.crt"
CherryPyWSGIServer.ssl_private_key = "/.ssl/server.key"
urls = (
'/(.*)', 'Hello',
)
app = web.application(urls, globals())
class Hello:
def GET(self, name):
return 'Hello World'
if __name__ == "__main__":
app.run()
错误是:
73.220.196.76:63982 - - [27/Nov/2018 06:56:50] "HTTP/1.1 GET /" - 200 OK
73.220.196.76:63982 - - [27/Nov/2018 06:56:50] "HTTP/1.1 GET /favicon.ico" - 200 OK
Exception in thread CP Server Thread-9:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 1375, in run
conn.communicate()
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 1269, in communicate
format_exc())
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 811, in simple_response
self.conn.wfile.sendall("".join(buf))
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 111, in sendall
*args, **kwargs)
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 61, in _safe_call
return call(*args, **kwargs)
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 913, in sendall
bytes_sent = self.send(data)
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 115, in send
*args, **kwargs)
File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 77, in _safe_call
raise socket.error(errnum)
error: -1
环境:Ubuntu 18.04.1 LTS Python 2.7.15rc1 web.py:0.39
有没有人看到这样的问题或知道可能导致它的原因。在webpy.org上阅读时。看来这是版本0.36的一个问题,但应该是好的0.37。我已经考虑过要0.40了,但犹豫不决,因为它还在开发中。
这可能不是一个正确的修复,但我做了以下黑客攻击,问题不再出现在我面前。我仍然在寻找一个更好的解决方案 - 可能完全抛弃CherryPy--但在那之前:
====>在def _safe_call
的ssl_pyopenssl.py
:替换
raise socket.error(errnum)
同
#### raise socket.error(errnum)
import sys
sys.stderr.write('===> ssl_pyopenssl: ignoring socket error' + str(errnum) + '\n')
return ""
####
以及raise socket.error(-1)
和raise wsgiserver.FatalSSLAlert(*e.args)
的类似补丁
====>在def sendall
的wsgiserver2.py
中:插入2行如下:
bytes_sent = self.send(data)
### insert the below two lines
if not bytes_sent: # hack b/c self.send has unhandled exceptions
break
### end insert
data = data[bytes_sent:]
有兴趣听到使用上述任何问题