使用cherryPy时线程中的Ubuntu / web.py异常出错 - python

我有一个正在使用的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_callssl_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 sendallwsgiserver2.py中====>:插入两行,如下所示:

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:]

有兴趣听到使用上述任何问题

为什么python模块报纸3k只为腾讯,新浪和wallettreetcn返回0篇文章? - python

news3k图书馆很棒。我上瘾了。我想问一下,为什么Source和build()只从大多数中国金融新闻页面返回0篇文章?我的代码有问题吗?from newspaper import Article, Source url='https://wallstreetcn.com/live/global' result=newspaper.Sou…

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…

python web.py异步执行外部程序 - python

我有一个内置的cherrypy服务器上运行的web.py应用程序。我想在用户发布到url时执行一个外部脚本,该脚本将在python子进程的后台运行.Popen调用和web.py将重定向到另一个页面,在该页面中使用jquery监视脚本的进度ajax请求。但是我无法在这里正确实现。代码段如下,如果需要,我可以提供更多信息。 import web from mul…

Python:检查是否存在维基百科文章 - python

我试图弄清楚如何检查Wikipedia文章是否存在。例如,https://en.wikipedia.org/wiki/Food 存在,但是https://en.wikipedia.org/wiki/Fod 不会,页面只是说:“维基百科没有此名称的文章。”谢谢! 参考方案 >>> import urllib >>> prin…

Python Pandas导出数据 - python

我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…